#pragma once #include "Command.hpp" #include #include namespace Echoion::Core { // !stats — global playback statistics. class StatsCommand : public Command { public: void execute(const CommandContext& ctx) override { auto db = ctx.service(); 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