Files
EchoionCore/include/echoion/core/commands/QueueCommand.hpp
T
2026-02-01 23:04:49 +03:00

96 lines
3.1 KiB
C++

#pragma once
#include "Command.hpp"
#include "echoion/core/Logger.hpp"
#include <format>
#include <sstream>
namespace Echoion::Core {
class QueueCommand : public Command {
public:
void execute(const CommandContext& ctx) override {
try {
auto manager = ctx.musicManager.lock();
if (!manager) {
ctx.reply("The music service is currently unavailable.");
return;
}
auto current = manager->getCurrentTrack();
auto queue = manager->getQueue();
auto state = manager->getPlaybackState();
if (!queue) {
ECHOION_LOG_ERROR(std::format("Queue command failed: {}", queue.error().message));
ctx.reply("Couldn't get queue information.");
return;
}
std::stringstream msg;
msg << "\xf0\x9f\x93\x9c **Queue**\n";
// Current track
if (current && current->has_value()) {
const auto& track = current->value();
msg << std::format("\n**Now Playing:** {} by {}\n",
track.track.title,
track.track.artist);
}
// Queue
if (queue->empty()) {
msg << "\nThe queue is empty. Add songs with [prefix]play!";
} else {
msg << std::format("\n**Up Next ({} tracks):**\n", queue->size());
for (size_t i = 0; i < queue->size() && i < 10; ++i) {
const auto& entry = (*queue)[i];
msg << std::format("{}. {}", i + 1, entry.track.title);
if (!entry.addedBy.empty()) {
msg << std::format(" (by {})", entry.addedBy);
}
msg << "\n";
}
if (queue->size() > 10) {
msg << std::format("\n... and {} more", queue->size() - 10);
}
}
// State indicators
if (state) {
msg << "\n\n";
if (state->isPaused) {
msg << "\xe2\x8f\xb8 Paused | ";
}
if (state->shuffle) {
msg << "\xf0\x9f\x94\x80 Shuffle | ";
}
if (state->repeat) {
msg << "\xf0\x9f\x94\x81 Repeat | ";
}
msg << std::format("Volume: {}%", static_cast<int>(state->volume * 100));
}
ctx.reply(msg.str());
} catch (const std::exception& e) {
ECHOION_LOG_ERROR(std::format("Queue command exception: {}", e.what()));
ctx.reply("Something went wrong. Please try again.");
}
}
std::string_view getDescription() const override {
return "Shows the current queue and playback status.";
}
CommandCategory getCategory() const override {
return CommandCategory::Queue;
}
std::vector<std::string_view> getAliases() const override {
return {"q", "list"};
}
};
} // namespace Echoion::Core