diff --git a/src/v2/autorespond/thanks/createResponse.ts b/src/v2/autorespond/thanks/createResponse.ts index 3e1f50d1..f929b71b 100644 --- a/src/v2/autorespond/thanks/createResponse.ts +++ b/src/v2/autorespond/thanks/createResponse.ts @@ -1,6 +1,6 @@ import { MessageButton } from 'discord.js'; import { MessageActionRow, MessageSelectMenu } from 'discord.js'; -import type { User, MessageOptions } from 'discord.js'; +import type { User, MessageOptions, Client } from 'discord.js'; import type { EmbedField, Collection } from 'discord.js'; import { clampLength } from '../../utils/clampStr.js'; @@ -8,23 +8,23 @@ import { createEmbed } from '../../utils/discordTools.js'; export function createResponse( thankedUsers: Collection, - authorId: string + authorId: string, + client: Client ): MessageOptions { const title = `Point${thankedUsers.size === 1 ? '' : 's'} received!`; - const description = `<@!${authorId}> has given a point to ${ - thankedUsers.size === 1 - ? `<@!${thankedUsers.first().id}>` - : 'the users mentioned below' - }!`; + const description = `<@!${authorId}> has given a point to ${thankedUsers.size === 1 + ? `<@!${thankedUsers.first().id}>` + : 'the users mentioned below' + }!`; const fields: EmbedField[] = thankedUsers.size > 1 ? [...thankedUsers].map(([, u], i) => ({ - inline: false, - name: `${(i + 1).toString()}.`, - value: `<@!${u.id}>`, - })) + inline: false, + name: `${(i + 1).toString()}.`, + value: `<@!${u.id}>`, + })) : []; const output = createEmbed({ @@ -36,26 +36,30 @@ export function createResponse( title, }).embed; + const clientId = client.user.id; + + const components = authorId === clientId ? [ + new MessageActionRow().addComponents( + thankedUsers.size > 1 + ? new MessageSelectMenu() + .setCustomId(`thanks🤔${authorId}🤔select`) + .setPlaceholder('Accidentally Thank someone? Un-thank them here!') + .setMinValues(1) + .setOptions( + thankedUsers.map(user => ({ + label: clampLength(user.username, 25), + value: user.id, + })) + ) + : new MessageButton() + .setCustomId(`thanks🤔${authorId}🤔${thankedUsers.first().id}`) + .setStyle('SECONDARY') + .setLabel('This was an accident, UNDO!') + ), + ] : []; + return { embeds: [output], - components: [ - new MessageActionRow().addComponents( - thankedUsers.size > 1 - ? new MessageSelectMenu() - .setCustomId(`thanks🤔${authorId}🤔select`) - .setPlaceholder('Accidentally Thank someone? Un-thank them here!') - .setMinValues(1) - .setOptions( - thankedUsers.map(user => ({ - label: clampLength(user.username, 25), - value: user.id, - })) - ) - : new MessageButton() - .setCustomId(`thanks🤔${authorId}🤔${thankedUsers.first().id}`) - .setStyle('SECONDARY') - .setLabel('This was an accident, UNDO!') - ), - ], + components, }; } diff --git a/src/v2/autorespond/thanks/index.ts b/src/v2/autorespond/thanks/index.ts index 02bcfd99..db4a4a30 100644 --- a/src/v2/autorespond/thanks/index.ts +++ b/src/v2/autorespond/thanks/index.ts @@ -36,12 +36,12 @@ const getReply = async (msg: Message): Promise => { } }; -const handleThanks = async (msg: Message): Promise => { +const handleThanks = async (msg: Message, client: Client): Promise => { const botId = msg.author.bot; const reply = await getReply(msg); if (botId || (msg.mentions.users.size === 0 && !reply)) { if ( - ['GUILD_PRIVATE_THREAD','GUILD_PUBLIC_THREAD'].includes(msg.channel.type) + ['GUILD_PRIVATE_THREAD', 'GUILD_PUBLIC_THREAD'].includes(msg.channel.type) ) { await handleThreadThanks(msg); } @@ -118,9 +118,8 @@ const handleThanks = async (msg: Message): Promise => { value: `<@!${u.id}>\n${diff} minute${diff === 1 ? '' : 's'}.`, }; }), - footerText: `You can only give a point to a user every ${POINT_LIMITER_IN_MINUTES} minute${ - Number.parseInt(POINT_LIMITER_IN_MINUTES) === 1 ? '' : 's' - }.`, + footerText: `You can only give a point to a user every ${POINT_LIMITER_IN_MINUTES} minute${Number.parseInt(POINT_LIMITER_IN_MINUTES) === 1 ? '' : 's' + }.`, provider: 'spam', title: 'Cooldown alert!', }).embed, @@ -134,7 +133,7 @@ const handleThanks = async (msg: Message): Promise => { } thankableUsers.forEach(async user => pointHandler(user.id, msg)); - const msgData = createResponse(thankableUsers, msg.author.id); + const msgData = createResponse(thankableUsers, msg.author.id, client); const response = await msg.channel.send(msgData); diff --git a/src/v2/autorespond/thanks/threadThanks.ts b/src/v2/autorespond/thanks/threadThanks.ts index 6ebd3f30..6f56ebe7 100644 --- a/src/v2/autorespond/thanks/threadThanks.ts +++ b/src/v2/autorespond/thanks/threadThanks.ts @@ -80,8 +80,7 @@ export async function handleThreadThanks(msg: Message): Promise { content: [ "Hey, it looks like you're trying to thank one or many users, but haven't specified who. Who would you like to thank?", alreadyThanked.length > 0 - ? _`There ${_.mapper({ 1: 'is' }, 'are')} **${_.n} user${ - _.s + ? _`There ${_.mapper({ 1: 'is' }, 'are')} **${_.n} user${_.s } that you can't thank as you've thanked them recently**, so they won't show up as an option.`( alreadyThanked.length ) @@ -160,7 +159,7 @@ export function attachThreadThanksHandler(client: Client): void { thankedMembers.map(item => [item.user.id, item.user]) ); - const responseData = createResponse(thankedUsers, user.id); + const responseData = createResponse(thankedUsers, user.id, client); let response: Message; const msg = await msgPromise; diff --git a/src/v2/index.ts b/src/v2/index.ts index 49c15c21..a4161a71 100644 --- a/src/v2/index.ts +++ b/src/v2/index.ts @@ -122,7 +122,7 @@ client.once('ready', async (): Promise => { try { await client.user.setAvatar('./logo.png'); - } catch {} + } catch { } }); const detectVarLimited = limitFnByUser(detectVar, { @@ -154,17 +154,17 @@ client.on('messageCreate', msg => { } if (NON_COMMAND_MSG_TYPES.has(msg.channel.type) && msg.guild) { - handleNonCommandGuildMessages(msg); + handleNonCommandGuildMessages(msg, client); } }); -const handleNonCommandGuildMessages = async (msg: Message) => { +const handleNonCommandGuildMessages = async (msg: Message, client: Client) => { const quoteLessContent = stripMarkdownQuote(msg.content); if (msg.author.bot) { return; } if (isWebdevAndWebDesignServer(msg) && isThanksMessage(quoteLessContent)) { - handleThanks(msg); + handleThanks(msg, client); } await detectDeprecatedCommands(msg); await detectJustAsk(msg);