mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-10 18:53:05 +00:00
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import {
|
|
Events,
|
|
MessageReaction,
|
|
PartialMessageReaction,
|
|
User,
|
|
PartialUser,
|
|
} from 'discord.js';
|
|
|
|
import { Event } from '@/types/EventTypes.js';
|
|
import {
|
|
decrementUserReactionCount,
|
|
incrementUserReactionCount,
|
|
} from '@/db/db.js';
|
|
import { processReactionAchievements } from '@/util/achievementManager.js';
|
|
|
|
export const reactionAdd: Event<typeof Events.MessageReactionAdd> = {
|
|
name: Events.MessageReactionAdd,
|
|
execute: async (
|
|
reaction: MessageReaction | PartialMessageReaction,
|
|
user: User | PartialUser,
|
|
) => {
|
|
try {
|
|
if (user.bot || !reaction.message.guild) return;
|
|
|
|
await incrementUserReactionCount(user.id);
|
|
|
|
await processReactionAchievements(user.id, reaction.message.guild);
|
|
} catch (error) {
|
|
console.error('Error handling reaction add:', error);
|
|
}
|
|
},
|
|
};
|
|
|
|
export const reactionRemove: Event<typeof Events.MessageReactionRemove> = {
|
|
name: Events.MessageReactionRemove,
|
|
execute: async (
|
|
reaction: MessageReaction | PartialMessageReaction,
|
|
user: User | PartialUser,
|
|
) => {
|
|
try {
|
|
if (user.bot || !reaction.message.guild) return;
|
|
|
|
await decrementUserReactionCount(user.id);
|
|
|
|
await processReactionAchievements(user.id, reaction.message.guild, true);
|
|
} catch (error) {
|
|
console.error('Error handling reaction remove:', error);
|
|
}
|
|
},
|
|
};
|
|
|
|
export default [reactionAdd, reactionRemove];
|