Files
faumaray 5c036d91fb making WEB
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-11 00:45:17 +03:00

56 lines
1.2 KiB
C++

#pragma once
#include "Command.hpp"
#include <Database.hpp>
#include <format>
namespace Echoion::Core
{
// !stats — global playback statistics.
class StatsCommand : public Command
{
public:
void execute(const CommandContext& ctx) override
{
auto db = ctx.service<Api::Database>();
if (!db) {
ctx.reply(
ctx.tr("Statistics are unavailable (no database)."));
return;
}
auto stats = db->getStatistics(0);
if (!stats) {
ctx.reply(ctx.tr("Couldn't read playback statistics."));
return;
}
const auto totalMinutes = stats->totalPlaytimeMs / 1000 / 60;
std::string msg = std::format(
"\xf0\x9f\x93\x8a Plays: {} {} Unique tracks: {} {} "
"Playtime: {}h {}m",
stats->totalPlays, kDot, stats->totalTracks, kDot,
totalMinutes / 60, totalMinutes % 60);
if (stats->mostPlayedTrack) {
msg += std::format("\nMost played: {} ({}x)",
trackLink(*stats->mostPlayedTrack),
stats->mostPlayedCount);
}
ctx.reply(msg);
}
std::string_view getDescription() const override
{
return "Show playback statistics";
}
CommandCategory getCategory() const override
{
return CommandCategory::Utility;
}
};
} // namespace Echoion::Core