Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(quoi-feur): quoi-feur with edited messages #138

Merged
merged 5 commits into from
May 4, 2024
Merged
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
@@ -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<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;
2 changes: 2 additions & 0 deletions src/modules/quoiFeur/quoiFeur.module.ts
Original file line number Diff line number Diff line change
@@ -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'],