Add Repeat Roll button
This commit is contained in:
parent
50d9c78b45
commit
a4ddce0bc8
|
@ -1,4 +1,4 @@
|
||||||
import { botId, DiscordenoMessage, Embed, FileContent, sendDirectMessage, sendMessage } from '@discordeno';
|
import { botId, ButtonStyles, DiscordenoMessage, Embed, FileContent, MessageComponentTypes, sendDirectMessage, sendMessage } from '@discordeno';
|
||||||
import { log, LogTypes as LT } from '@Log4Deno';
|
import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
|
|
||||||
import config from '~config';
|
import config from '~config';
|
||||||
|
@ -13,15 +13,18 @@ import { ApiResolveMap, TestResolveMap } from 'artigen/managers/resolveManager.t
|
||||||
|
|
||||||
import { generateCountDetailsEmbed, generateDMFailed, generateRollDistsEmbed, generateRollEmbed, toggleWebView } from 'artigen/utils/embeds.ts';
|
import { generateCountDetailsEmbed, generateDMFailed, generateRollDistsEmbed, generateRollEmbed, toggleWebView } from 'artigen/utils/embeds.ts';
|
||||||
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
import { loggingEnabled } from 'artigen/utils/logFlag.ts';
|
||||||
|
import { basicReducer } from 'artigen/utils/reducers.ts';
|
||||||
|
|
||||||
import dbClient from 'db/client.ts';
|
import dbClient from 'db/client.ts';
|
||||||
import { queries } from 'db/common.ts';
|
import { queries } from 'db/common.ts';
|
||||||
|
|
||||||
|
import { infoColor1 } from 'embeds/colors.ts';
|
||||||
|
|
||||||
import stdResp from 'endpoints/stdResponses.ts';
|
import stdResp from 'endpoints/stdResponses.ts';
|
||||||
|
|
||||||
|
import { InteractionValueSeparator } from 'events/interactionCreate.ts';
|
||||||
|
|
||||||
import utils from 'utils/utils.ts';
|
import utils from 'utils/utils.ts';
|
||||||
import { infoColor1 } from 'embeds/colors.ts';
|
|
||||||
import { basicReducer } from 'artigen/utils/reducers.ts';
|
|
||||||
|
|
||||||
const getUserIdForEmbed = (rollRequest: QueuedRoll): bigint => {
|
const getUserIdForEmbed = (rollRequest: QueuedRoll): bigint => {
|
||||||
if (rollRequest.apiRoll) return rollRequest.api.userId;
|
if (rollRequest.apiRoll) return rollRequest.api.userId;
|
||||||
|
@ -29,6 +32,8 @@ const getUserIdForEmbed = (rollRequest: QueuedRoll): bigint => {
|
||||||
return 0n;
|
return 0n;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const repeatRollCustomId = 'repeatRoll';
|
||||||
|
|
||||||
export const onWorkerComplete = async (workerMessage: MessageEvent<SolvedRoll>, workerTimeout: number, rollRequest: QueuedRoll) => {
|
export const onWorkerComplete = async (workerMessage: MessageEvent<SolvedRoll>, workerTimeout: number, rollRequest: QueuedRoll) => {
|
||||||
const apiResolve = rollRequest.apiRoll ? ApiResolveMap.get(rollRequest.resolve as string) : undefined;
|
const apiResolve = rollRequest.apiRoll ? ApiResolveMap.get(rollRequest.resolve as string) : undefined;
|
||||||
const testResolve = rollRequest.testRoll ? TestResolveMap.get(rollRequest.resolve as string) : undefined;
|
const testResolve = rollRequest.testRoll ? TestResolveMap.get(rollRequest.resolve as string) : undefined;
|
||||||
|
@ -183,6 +188,20 @@ export const onWorkerComplete = async (workerMessage: MessageEvent<SolvedRoll>,
|
||||||
} else {
|
} else {
|
||||||
newMsg = await rollRequest.dd.myResponse.edit({
|
newMsg = await rollRequest.dd.myResponse.edit({
|
||||||
embeds: pubEmbeds,
|
embeds: pubEmbeds,
|
||||||
|
components: [
|
||||||
|
{
|
||||||
|
type: MessageComponentTypes.ActionRow,
|
||||||
|
components: [
|
||||||
|
{
|
||||||
|
type: MessageComponentTypes.Button,
|
||||||
|
label: 'Repeat Roll',
|
||||||
|
customId: `${repeatRollCustomId}${InteractionValueSeparator}${getUserIdForEmbed(rollRequest).toString()}`,
|
||||||
|
style: ButtonStyles.Secondary,
|
||||||
|
emoji: '🎲',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,14 +254,14 @@ Please click on "<@${botId}> *Click to see attachment*" above this message to se
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
rollRequest.modifiers.count
|
rollRequest.modifiers.count
|
||||||
? {
|
? {
|
||||||
counts: returnMsg.counts,
|
counts: returnMsg.counts,
|
||||||
details: pubEmbedDetails,
|
details: pubEmbedDetails,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
details: pubEmbedDetails,
|
details: pubEmbedDetails,
|
||||||
},
|
}
|
||||||
),
|
)
|
||||||
),
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -253,13 +272,12 @@ Please click on "<@${botId}> *Click to see attachment*" above this message to se
|
||||||
(
|
(
|
||||||
await generateRollEmbed(
|
await generateRollEmbed(
|
||||||
rollRequest.dd.originalMessage.authorId,
|
rollRequest.dd.originalMessage.authorId,
|
||||||
<SolvedRoll> {
|
<SolvedRoll>{
|
||||||
error: true,
|
error: true,
|
||||||
errorMsg:
|
errorMsg: `Something weird went wrong, likely the requested roll is too complex and caused the response to be too large for Discord. Try breaking the request down into smaller messages and try again.\n\nIf this error continues to come up, please \`${config.prefix}report\` this to my developer.`,
|
||||||
`Something weird went wrong, likely the requested roll is too complex and caused the response to be too large for Discord. Try breaking the request down into smaller messages and try again.\n\nIf this error continues to come up, please \`${config.prefix}report\` this to my developer.`,
|
|
||||||
errorCode: 'UnhandledWorkerComplete',
|
errorCode: 'UnhandledWorkerComplete',
|
||||||
},
|
},
|
||||||
<RollModifiers> {},
|
<RollModifiers>{}
|
||||||
)
|
)
|
||||||
).embed,
|
).embed,
|
||||||
],
|
],
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
DiscordenoMessage,
|
DiscordenoMessage,
|
||||||
DiscordMessageComponentTypes,
|
DiscordMessageComponentTypes,
|
||||||
editMessage,
|
editMessage,
|
||||||
|
getMessage,
|
||||||
Interaction,
|
Interaction,
|
||||||
InteractionResponseTypes,
|
InteractionResponseTypes,
|
||||||
MessageFlags,
|
MessageFlags,
|
||||||
|
@ -12,12 +13,16 @@ import {
|
||||||
} from '@discordeno';
|
} from '@discordeno';
|
||||||
import { log, LogTypes as LT } from '@Log4Deno';
|
import { log, LogTypes as LT } from '@Log4Deno';
|
||||||
|
|
||||||
|
import { repeatRollCustomId } from 'artigen/managers/handler/workerComplete.ts';
|
||||||
|
|
||||||
import { toggleWebView, webViewCustomId } from 'artigen/utils/embeds.ts';
|
import { toggleWebView, webViewCustomId } from 'artigen/utils/embeds.ts';
|
||||||
|
|
||||||
import { generateHelpMessage, helpCustomId } from 'commands/helpLibrary/generateHelpMessage.ts';
|
import { generateHelpMessage, helpCustomId } from 'commands/helpLibrary/generateHelpMessage.ts';
|
||||||
|
|
||||||
import { failColor } from 'embeds/colors.ts';
|
import { failColor } from 'embeds/colors.ts';
|
||||||
|
|
||||||
|
import { messageCreateHandler } from 'events/messageCreate.ts';
|
||||||
|
|
||||||
import utils from 'utils/utils.ts';
|
import utils from 'utils/utils.ts';
|
||||||
|
|
||||||
export const InteractionValueSeparator = '\u205a';
|
export const InteractionValueSeparator = '\u205a';
|
||||||
|
@ -43,7 +48,7 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedData.customId.startsWith(webViewCustomId) && parsedData.componentType === DiscordMessageComponentTypes.Button && interaction.message) {
|
if (parsedData.customId.startsWith(webViewCustomId) && interaction.message) {
|
||||||
const ownerId = parsedData.customId.split(InteractionValueSeparator)[1] ?? 'missingOwnerId';
|
const ownerId = parsedData.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) {
|
||||||
|
@ -70,6 +75,35 @@ export const interactionCreateHandler = async (interaction: Interaction) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parsedData.customId.startsWith(repeatRollCustomId) && interaction.message) {
|
||||||
|
const ownerId = parsedData.customId.split(InteractionValueSeparator)[1] ?? 'missingOwnerId';
|
||||||
|
const userInteractingId = interaction.member?.user.id ?? interaction.user?.id ?? 'missingUserId';
|
||||||
|
if (ownerId === userInteractingId) {
|
||||||
|
ackInteraction(interaction);
|
||||||
|
const botMsg: DiscordenoMessage = await structures.createDiscordenoMessage(interaction.message);
|
||||||
|
const rollMsg: DiscordenoMessage = await getMessage(
|
||||||
|
BigInt(botMsg.messageReference?.channelId ?? '0'),
|
||||||
|
BigInt(botMsg.messageReference?.messageId ?? '0'),
|
||||||
|
);
|
||||||
|
messageCreateHandler(rollMsg);
|
||||||
|
} else {
|
||||||
|
sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
|
data: {
|
||||||
|
flags: MessageFlags.Empheral,
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
color: failColor,
|
||||||
|
title: 'Not Allowed!',
|
||||||
|
description: 'Only the original user that requested this roll can repeat it.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}).catch((e) => utils.commonLoggers.messageSendError('interactionCreate.ts:96', interaction, e));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log(LT.WARN, `UNHANDLED INTERACTION!!! data: ${JSON.stringify(interaction.data)} | Full Interaction: ${JSON.stringify(interaction)}`);
|
log(LT.WARN, `UNHANDLED INTERACTION!!! 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)}`);
|
||||||
|
|
|
@ -23,8 +23,7 @@ export const messageCreateHandler = (message: DiscordenoMessage) => {
|
||||||
|
|
||||||
// Handle inline guilds if allowed
|
// Handle inline guilds if allowed
|
||||||
if (inlineList.includes(message.guildId) && message.content.includes(config.prefix) && message.content.includes(config.prefix)) {
|
if (inlineList.includes(message.guildId) && message.content.includes(config.prefix) && message.content.includes(config.prefix)) {
|
||||||
const argSpaces = message.content.trim().split(/([ \n]+)/g);
|
commands.roll(message, message.content.trim().split(/([ \n]+)/g), '');
|
||||||
commands.roll(message, argSpaces, '');
|
|
||||||
}
|
}
|
||||||
// return as we are done handling this message
|
// return as we are done handling this message
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue