Skip to content

Commit

Permalink
more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
IRONM00N committed Nov 28, 2023
1 parent b48f734 commit dcd02d2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/commands/leveling/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,40 @@ export default class LevelCommand extends BotCommand {
}

private async getImage(user: User, guild: Guild, pref: string): Promise<Buffer> {
performance.mark(`${pref}:image:start`);
const mark = (name: string) => {
this.logger.debug(`mark: ${name}`);
performance.mark(`${pref}:${name}`);
};

mark(`image:start`);

const guildRows = await Level.findAll({ where: { guild: guild.id } });

performance.mark(`${pref}:image:rows`);
mark(`image:rows`);

this.logger.debug(`guildRows: ${guildRows.length}`);

const rank = guildRows.sort((a, b) => b.xp - a.xp);

performance.mark(`${pref}:image:sort`);
mark(`image:sort`);

const userLevelRow = guildRows.find((a) => a.user === user.id);

performance.mark(`${pref}:image:find`);
mark(`image:find`);

if (!userLevelRow) throw new Error('User does not have a level');
const userLevel = userLevelRow.level;
const currentLevelXP = Level.convertLevelToXp(userLevel);
const currentLevelXpProgress = userLevelRow.xp - currentLevelXP;
const xpForNextLevel = Level.convertLevelToXp(userLevelRow.level + 1) - currentLevelXP;

performance.mark(`${pref}:image:convert`);
mark(`image:convert`);

this.logger.debug(`hexAccentColor: ${user.hexAccentColor}`);

await user.fetch(true); // get accent color

performance.mark(`${pref}:image:fetch`);
mark(`image:fetch`);

const white = '#FFFFFF',
gray = '#23272A',
Expand Down Expand Up @@ -191,16 +198,16 @@ export default class LevelCommand extends BotCommand {

const xpTxt = `${simplifyNumber(currentLevelXpProgress)}/${simplifyNumber(xpForNextLevel)}`;

const rankTxt = simplifyNumber(rank.indexOf(rank.find((x) => x.user === user.id)!) + 1);
const rankTxt = simplifyNumber(rank.indexOf(userLevelRow) + 1);

ctx.fillText(`Level: ${userLevel} XP: ${xpTxt} Rank: ${rankTxt}`, AVATAR_SIZE + 70, AVATAR_SIZE - 20);

performance.mark(`${pref}:image:draw`);
mark(`image:draw`);

// Return image in buffer form
const buf = levelCard.toBuffer('image/png');

performance.mark(`${pref}:image:buffer`);
mark(`image:buffer`);

return buf;
}
Expand Down

0 comments on commit dcd02d2

Please sign in to comment.