Skip to content

Commit 52d35e4

Browse files
adfaurepotb
andauthoredMay 4, 2024··
fix(quoi-feur): quoi-feur with edited messages (#138)
Co-authored-by: Peïo Thibault <peio.thibault@gmail.com>
1 parent b0b75f6 commit 52d35e4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎src/modules/quoiFeur/quoiFeur.helpers.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import {
22
ChannelType,
33
type ChatInputCommandInteraction,
44
DMChannel,
5-
type Message,
5+
Message,
66
type NonThreadGuildBasedChannel,
7+
type PartialMessage,
78
} from 'discord.js';
89

910
import { cache } from '../../core/cache';
@@ -62,6 +63,25 @@ export const reactOnEndWithQuoi = async (message: Message) => {
6263
await reactWithFeur(message);
6364
};
6465

66+
export const reactOnEndWithQuoiUpdated = async (
67+
_oldMessage: Message | PartialMessage,
68+
newMessage: Message | PartialMessage,
69+
) => {
70+
if (!(newMessage instanceof Message)) return;
71+
72+
// Both E and U are in feur and coubeh, that should be sufficient to detect if the bot has already reacted
73+
const feurCoubeh = new Set<string>([EMOJI.E, EMOJI.U]);
74+
75+
// Check if the old message already has a reaction
76+
const selfReactions = newMessage.reactions.cache.some((reaction) => {
77+
return reaction.me && reaction.emoji.name && feurCoubeh.has(reaction.emoji.name);
78+
});
79+
80+
if (selfReactions) return;
81+
82+
await reactOnEndWithQuoi(newMessage);
83+
};
84+
6585
export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteraction) => {
6686
const { channel } = interaction;
6787
if (!channel || !channel.isTextBased() || channel.type !== ChannelType.GuildText) return;

‎src/modules/quoiFeur/quoiFeur.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
addQuoiFeurToChannel,
66
cleanCacheOnChannelDelete,
77
reactOnEndWithQuoi,
8+
reactOnEndWithQuoiUpdated,
89
removeQuoiFeurFromChannel,
910
} from './quoiFeur.helpers';
1011

@@ -31,6 +32,7 @@ export const quoiFeur = createModule({
3132
],
3233
eventHandlers: () => ({
3334
messageCreate: reactOnEndWithQuoi,
35+
messageUpdate: reactOnEndWithQuoiUpdated,
3436
channelDelete: cleanCacheOnChannelDelete,
3537
}),
3638
intents: ['Guilds', 'GuildMessages', 'MessageContent', 'GuildMessageReactions'],

0 commit comments

Comments
 (0)
Please sign in to comment.