Skip to content

Commit

Permalink
Limit stats to top 10 emotes
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Jul 16, 2024
1 parent 062c363 commit ab38ef9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/commands/emoteStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class EmoteStatsCommand implements ApplicationCommand {
.setDescription(this.description);

async handleInteraction(command: CommandInteraction, context: BotContext): Promise<void> {
const stats = await emoteLogging.getUserStats(command.user);
const stats = await emoteLogging.getUserStats(command.user, 10);
const totalEmotes = Math.sumPrecise(stats.map(s => s.count)) | 0;
await command.reply({
embeds: [
Expand Down
4 changes: 2 additions & 2 deletions src/service/emoteLogging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ export async function persistCurrentGuildEmotes(context: BotContext) {
}
}

export async function getUserStats(user: User) {
return dbEmote.getUsage(user);
export async function getUserStats(user: User, limit: number) {
return dbEmote.getUsage(user, limit | 0);
}
3 changes: 2 additions & 1 deletion src/storage/emote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function markAsDeleted(emoteId: Emote["id"], ctx = db()): Promise<v
.execute();
}

export async function getUsage(user: User, ctx = db()) {
export async function getUsage(user: User, limit: number, ctx = db()) {
return await ctx
.selectFrom("emoteUse")
.innerJoin("emote", "emote.id", "emoteUse.emoteId")
Expand All @@ -120,5 +120,6 @@ export async function getUsage(user: User, ctx = db()) {
sql<number>`COUNT(*)`.as("count"),
])
.orderBy(sql<number>`COUNT(*)`, "desc")
.limit(limit)
.execute();
}

0 comments on commit ab38ef9

Please sign in to comment.