prep for app commands
This commit is contained in:
parent
6d731951c7
commit
633e786d95
|
@ -1,13 +1,12 @@
|
||||||
import {
|
import {
|
||||||
ButtonData,
|
|
||||||
DiscordenoMessage,
|
DiscordenoMessage,
|
||||||
DiscordMessageComponentTypes,
|
DiscordMessageComponentTypes,
|
||||||
editMessage,
|
editMessage,
|
||||||
getMessage,
|
getMessage,
|
||||||
Interaction,
|
Interaction,
|
||||||
InteractionResponseTypes,
|
InteractionResponseTypes,
|
||||||
|
InteractionTypes,
|
||||||
MessageFlags,
|
MessageFlags,
|
||||||
SelectMenuData,
|
|
||||||
sendInteractionResponse,
|
sendInteractionResponse,
|
||||||
structures,
|
structures,
|
||||||
} from '@discordeno';
|
} from '@discordeno';
|
||||||
|
@ -34,26 +33,24 @@ const ackInteraction = (interaction: Interaction) =>
|
||||||
|
|
||||||
export const interactionCreateHandler = async (interaction: Interaction) => {
|
export const interactionCreateHandler = async (interaction: Interaction) => {
|
||||||
try {
|
try {
|
||||||
if (interaction.data) {
|
if (interaction.type === InteractionTypes.MessageComponent && interaction.data) {
|
||||||
const parsedData = JSON.parse(JSON.stringify(interaction.data)) as SelectMenuData | ButtonData;
|
if (interaction.data.customId.startsWith(helpCustomId) && interaction.data.componentType === DiscordMessageComponentTypes.SelectMenu) {
|
||||||
|
|
||||||
if (parsedData.customId.startsWith(helpCustomId) && parsedData.componentType === DiscordMessageComponentTypes.SelectMenu) {
|
|
||||||
// Acknowledge the request since we're editing the original message
|
// Acknowledge the request since we're editing the original message
|
||||||
ackInteraction(interaction);
|
ackInteraction(interaction);
|
||||||
|
|
||||||
// Edit original message
|
// Edit original message
|
||||||
editMessage(BigInt(interaction.channelId ?? '0'), BigInt(interaction.message?.id ?? '0'), generateHelpMessage(parsedData.values[0])).catch((e) =>
|
editMessage(BigInt(interaction.channelId ?? '0'), BigInt(interaction.message?.id ?? '0'), generateHelpMessage(interaction.data.values[0])).catch((e) =>
|
||||||
utils.commonLoggers.messageEditError('interactionCreate.ts:30', interaction, e)
|
utils.commonLoggers.messageEditError('interactionCreate.ts:30', interaction, e)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedData.customId.startsWith(webViewCustomId) && interaction.message) {
|
if (interaction.data.customId.startsWith(webViewCustomId) && interaction.message) {
|
||||||
const ownerId = parsedData.customId.split(InteractionValueSeparator)[1] ?? 'missingOwnerId';
|
const ownerId = interaction.data.customId.split(InteractionValueSeparator)[1] ?? 'missingOwnerId';
|
||||||
const userInteractingId = interaction.member?.user.id ?? interaction.user?.id ?? 'missingUserId';
|
const userInteractingId = interaction.member?.user.id ?? interaction.user?.id ?? 'missingUserId';
|
||||||
if (ownerId === userInteractingId) {
|
if (ownerId === userInteractingId) {
|
||||||
ackInteraction(interaction);
|
ackInteraction(interaction);
|
||||||
const enableWebView = parsedData.customId.split(InteractionValueSeparator)[2] === 'enable';
|
const enableWebView = interaction.data.customId.split(InteractionValueSeparator)[2] === 'enable';
|
||||||
const ddMsg: DiscordenoMessage = await structures.createDiscordenoMessage(interaction.message);
|
const ddMsg: DiscordenoMessage = await structures.createDiscordenoMessage(interaction.message);
|
||||||
|
|
||||||
toggleWebView(ddMsg, ownerId, enableWebView);
|
toggleWebView(ddMsg, ownerId, enableWebView);
|
||||||
|
@ -75,8 +72,8 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedData.customId.startsWith(repeatRollCustomId) && interaction.message) {
|
if (interaction.data.customId.startsWith(repeatRollCustomId) && interaction.message) {
|
||||||
const ownerId = parsedData.customId.split(InteractionValueSeparator)[1] ?? 'missingOwnerId';
|
const ownerId = interaction.data.customId.split(InteractionValueSeparator)[1] ?? 'missingOwnerId';
|
||||||
const userInteractingId = interaction.member?.user.id ?? interaction.user?.id ?? 'missingUserId';
|
const userInteractingId = interaction.member?.user.id ?? interaction.user?.id ?? 'missingUserId';
|
||||||
if (ownerId === userInteractingId) {
|
if (ownerId === userInteractingId) {
|
||||||
ackInteraction(interaction);
|
ackInteraction(interaction);
|
||||||
|
@ -104,9 +101,11 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(LT.WARN, `UNHANDLED INTERACTION!!! data: ${JSON.stringify(interaction.data)} | Full Interaction: ${JSON.stringify(interaction)}`);
|
log(LT.WARN, `UNHANDLED COMPONENT!!! data: ${JSON.stringify(interaction.data)} | Full Interaction: ${JSON.stringify(interaction)}`);
|
||||||
|
} else if (interaction.type === InteractionTypes.ApplicationCommand && interaction.data) {
|
||||||
|
log(LT.WARN, `UNHANDLED APPLICATION COMMAND!!! data: ${JSON.stringify(interaction.data)} | Full Interaction: ${JSON.stringify(interaction)}`);
|
||||||
} else {
|
} else {
|
||||||
log(LT.WARN, `UNHANDLED INTERACTION!!! Missing data! ${JSON.stringify(interaction)}`);
|
log(LT.WARN, `UNHANDLED INTERACTION!!! Missing data! ${JSON.stringify(interaction)} | Full Interaction: ${JSON.stringify(interaction)}`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(LT.ERROR, `UNHANDLED INTERACTION!!! ERR! interaction: ${JSON.stringify(interaction)} error: ${JSON.stringify(e)}`);
|
log(LT.ERROR, `UNHANDLED INTERACTION!!! ERR! interaction: ${JSON.stringify(interaction)} error: ${JSON.stringify(e)}`);
|
||||||
|
|
Loading…
Reference in New Issue