Bugfix to stats

This commit is contained in:
Erik 2024-03-29 16:25:57 +02:00
parent f47250c834
commit 092856138c
2 changed files with 4 additions and 2 deletions

View File

@ -188,7 +188,7 @@ class MusicLibrary implements Initialisable
} }
else else
{ {
const entry = { ...defaultStats }; const entry: MusicStatsEntry = { ...defaultStats, name };
(entry[stat] as number)++; (entry[stat] as number)++;
this.#stats.set(name, entry); this.#stats.set(name, entry);
} }

View File

@ -31,13 +31,15 @@ class StatsCommand extends Command
const mostPlayed = stats.sort((a, b) => b.plays - a.plays).slice(0, 10); const mostPlayed = stats.sort((a, b) => b.plays - a.plays).slice(0, 10);
const mostSkipped = stats.sort((a, b) => b.skips - a.skips).slice(0, 10); const mostSkipped = stats.sort((a, b) => b.skips - a.skips).slice(0, 10);
let stat = 'plays';
const mapper = (entry: MusicStatsEntry, pos: number) => const mapper = (entry: MusicStatsEntry, pos: number) =>
{ {
pos++; pos++;
const [ idx ] = this.client.musicPlayer.library.search({ title: entry.name }); const [ idx ] = this.client.musicPlayer.library.search({ title: entry.name });
return `\t[${('00' + pos).slice(-2)}] **${idx.title}** by ${idx.artist}`; return `\t[${('00' + pos).slice(-2)}]\t**${idx.title}** by ${idx.artist} (${entry[stat]})`;
}; };
const top10Plays = mostPlayed.map(mapper).join('\n'); const top10Plays = mostPlayed.map(mapper).join('\n');
stat = 'skips';
const top10Skips = mostSkipped.map(mapper).join('\n'); const top10Skips = mostSkipped.map(mapper).join('\n');
return `**Music statistics**\n\nMost played:\n${top10Plays}\n\nMost skipped:\n${top10Skips}`; return `**Music statistics**\n\nMost played:\n${top10Plays}\n\nMost skipped:\n${top10Skips}`;
} }