feat(arabot): add more information on ranks

This commit is contained in:
smyalygames 2023-03-15 00:12:49 +00:00
parent f1453d5691
commit 528f592733
2 changed files with 9 additions and 4 deletions

View File

@ -20,7 +20,7 @@
import { Args, Command, RegisterBehavior } from '@sapphire/framework';
import type { User, Guild, Message } from 'discord.js';
import { EmbedBuilder } from 'discord.js';
import { getRank } from '#utils/database/xp';
import { getRank, xpToNextLevel } from '#utils/database/xp';
export class RankCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
@ -119,13 +119,16 @@ export class RankCommand extends Command {
const rank = await getRank(user.id);
const xpNextLevel = xpToNextLevel(rank.level, 0);
const embed = new EmbedBuilder()
.setColor('#00ff7d')
.setAuthor({ name: `${member.displayName}'s Rank`, iconURL: `${user.displayAvatarURL()}` })
.addFields(
{ name: 'Rank', value: `${rank.rank}` },
{ name: 'Level', value: `${rank.level}`, inline: true },
{ name: 'XP', value: `${rank.xp}`, inline: true },
{ name: 'Level', value: `${rank.level} (${rank.xpNextLevel}/${xpNextLevel} XP)`, inline: true },
{ name: 'Total XP', value: `${rank.xp}`, inline: true },
{ name: 'Total messages', value: `${rank.xpNextLevel}` },
);
info.success = true;

View File

@ -2,7 +2,7 @@ import { container } from '@sapphire/framework';
import { Time } from '@sapphire/time-utilities';
import type { Snowflake } from 'discord.js';
function xpToNextLevel(level: number, xp: number) {
export function xpToNextLevel(level: number, xp: number) {
return 5 * (level * level) + (50 * level) + 100 - xp;
}
@ -90,6 +90,7 @@ export async function getRank(userId: Snowflake) {
rank: 0,
level: 0,
xp: 0,
xpNextLevel: 0,
};
if (user === null) {
@ -109,6 +110,7 @@ export async function getRank(userId: Snowflake) {
info.level = user.level;
info.xp = user.xp;
info.xpNextLevel = user.xpForNextLevel;
return info;
}