Skip to content

Commit

Permalink
fix(quoi-feur): quoi-feur with edited messages (#138)
Browse files Browse the repository at this point in the history
Co-authored-by: Peïo Thibault <[email protected]>
  • Loading branch information
adfaure and potb authored May 4, 2024
1 parent b0b75f6 commit 52d35e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/modules/quoiFeur/quoiFeur.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {
ChannelType,
type ChatInputCommandInteraction,
DMChannel,
type Message,
Message,
type NonThreadGuildBasedChannel,
type PartialMessage,
} from 'discord.js';

import { cache } from '../../core/cache';
Expand Down Expand Up @@ -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<string>([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;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/quoiFeur/quoiFeur.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
addQuoiFeurToChannel,
cleanCacheOnChannelDelete,
reactOnEndWithQuoi,
reactOnEndWithQuoiUpdated,
removeQuoiFeurFromChannel,
} from './quoiFeur.helpers';

Expand All @@ -31,6 +32,7 @@ export const quoiFeur = createModule({
],
eventHandlers: () => ({
messageCreate: reactOnEndWithQuoi,
messageUpdate: reactOnEndWithQuoiUpdated,
channelDelete: cleanCacheOnChannelDelete,
}),
intents: ['Guilds', 'GuildMessages', 'MessageContent', 'GuildMessageReactions'],
Expand Down

0 comments on commit 52d35e4

Please sign in to comment.