feat(arabot): add emitter when user levels up

This commit is contained in:
Anthony Berg 2024-08-07 01:38:16 +02:00
parent a09b007831
commit 3009a0f923
2 changed files with 14 additions and 2 deletions

View File

@ -46,6 +46,12 @@ export class XpListener extends Listener {
const xp = randint(15, 25);
await addXp(user.id, xp);
const level = await addXp(user.id, xp);
// Emits that a user has leveled up
if (level !== null) {
this.container.logger.info('User is levelling up!');
this.container.client.emit('xpLevelUp', message.member, level);
}
}
}

View File

@ -36,7 +36,7 @@ export async function addXp(userId: Snowflake, xp: number) {
}
}
await container.database.xp.upsert({
const info = await container.database.xp.upsert({
where: {
userId,
},
@ -63,6 +63,12 @@ export async function addXp(userId: Snowflake, xp: number) {
xpForNextLevel: xp,
},
});
if (level === 1) {
return info.level;
} else {
return null;
}
}
export async function checkCanAddXp(userId: Snowflake) {