mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-09-16 21:22:21 +02:00
feat(arabot): add emitter when user levels up
This commit is contained in:
parent
a09b007831
commit
3009a0f923
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user