mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-11 19:23:06 +00:00
feat: add achievement system
Signed-off-by: Ahmad <103906421+ahmadk953@users.noreply.github.com>
This commit is contained in:
parent
830838a6a1
commit
2f5c3499e7
15 changed files with 1966 additions and 37 deletions
|
@ -11,6 +11,7 @@ import { approveFact, deleteFact } from '@/db/db.js';
|
|||
import * as GiveawayManager from '@/util/giveaways/giveawayManager.js';
|
||||
import { ExtendedClient } from '@/structures/ExtendedClient.js';
|
||||
import { safelyRespond, validateInteraction } from '@/util/helpers.js';
|
||||
import { processCommandAchievements } from '@/util/achievementManager.js';
|
||||
|
||||
export default {
|
||||
name: Events.InteractionCreate,
|
||||
|
@ -48,12 +49,22 @@ async function handleCommand(interaction: Interaction) {
|
|||
|
||||
if (interaction.isChatInputCommand()) {
|
||||
await command.execute(interaction);
|
||||
await processCommandAchievements(
|
||||
interaction.user.id,
|
||||
command.data.name,
|
||||
interaction.guild!,
|
||||
);
|
||||
} else if (
|
||||
interaction.isUserContextMenuCommand() ||
|
||||
interaction.isMessageContextMenuCommand()
|
||||
) {
|
||||
// @ts-expect-error
|
||||
await command.execute(interaction);
|
||||
await processCommandAchievements(
|
||||
interaction.user.id,
|
||||
command.data.name,
|
||||
interaction.guild!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
checkAndAssignLevelRoles,
|
||||
processMessage,
|
||||
} from '@/util/levelingSystem.js';
|
||||
import { processLevelUpAchievements } from '@/util/achievementManager.js';
|
||||
|
||||
export const messageDelete: Event<typeof Events.MessageDelete> = {
|
||||
name: Events.MessageDelete,
|
||||
|
@ -102,6 +103,12 @@ export const messageCreate: Event<typeof Events.MessageCreate> = {
|
|||
levelResult.newLevel,
|
||||
);
|
||||
|
||||
await processLevelUpAchievements(
|
||||
message.author.id,
|
||||
levelResult.newLevel,
|
||||
message.guild,
|
||||
);
|
||||
|
||||
if (assignedRole) {
|
||||
await advancementsChannel.send(
|
||||
`<@${message.author.id}> You've earned the <@&${assignedRole}> role!`,
|
||||
|
|
52
src/events/reactionEvents.ts
Normal file
52
src/events/reactionEvents.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
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];
|
Loading…
Add table
Add a link
Reference in a new issue