diff --git a/src/modules/quoiFeur/quoiFeur.helpers.ts b/src/modules/quoiFeur/quoiFeur.helpers.ts index 417c7bb..b88af96 100644 --- a/src/modules/quoiFeur/quoiFeur.helpers.ts +++ b/src/modules/quoiFeur/quoiFeur.helpers.ts @@ -2,8 +2,9 @@ import { ChannelType, type ChatInputCommandInteraction, DMChannel, - type Message, + Message, type NonThreadGuildBasedChannel, + type PartialMessage, } from 'discord.js'; import { cache } from '../../core/cache'; @@ -62,6 +63,25 @@ export const reactOnEndWithQuoi = async (message: Message) => { await reactWithFeur(message); }; +export const reactOnEndWithQuoiUpdated = async ( + _oldMessage: Message | PartialMessage, + newMessage: Message | PartialMessage, +) => { + if (!(newMessage instanceof Message)) return; + + // Both E and U are in feur and coubeh, that should be sufficient to detect if the bot has already reacted + const feurCoubeh = new Set([EMOJI.E, EMOJI.U]); + + // Check if the old message already has a reaction + const selfReactions = newMessage.reactions.cache.some((reaction) => { + return reaction.me && reaction.emoji.name && feurCoubeh.has(reaction.emoji.name); + }); + + if (selfReactions) return; + + await reactOnEndWithQuoi(newMessage); +}; + export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteraction) => { const { channel } = interaction; if (!channel || !channel.isTextBased() || channel.type !== ChannelType.GuildText) return; diff --git a/src/modules/quoiFeur/quoiFeur.module.ts b/src/modules/quoiFeur/quoiFeur.module.ts index 4274f3a..6f84af5 100644 --- a/src/modules/quoiFeur/quoiFeur.module.ts +++ b/src/modules/quoiFeur/quoiFeur.module.ts @@ -5,6 +5,7 @@ import { addQuoiFeurToChannel, cleanCacheOnChannelDelete, reactOnEndWithQuoi, + reactOnEndWithQuoiUpdated, removeQuoiFeurFromChannel, } from './quoiFeur.helpers'; @@ -31,6 +32,7 @@ export const quoiFeur = createModule({ ], eventHandlers: () => ({ messageCreate: reactOnEndWithQuoi, + messageUpdate: reactOnEndWithQuoiUpdated, channelDelete: cleanCacheOnChannelDelete, }), intents: ['Guilds', 'GuildMessages', 'MessageContent', 'GuildMessageReactions'],