Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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