Files
EchoionCore/include/echoion/core/commands/RemoveCommand.hpp
T
faumaray 5c036d91fb making WEB
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-11 00:45:17 +03:00

95 lines
2.2 KiB
C++

#pragma once
#include "Command.hpp"
#include <Void/Log/Log.hpp>
#include <charconv>
#include <format>
namespace Echoion::Core
{
class RemoveCommand : public Command
{
public:
void execute(const CommandContext& ctx) override
{
try {
auto manager = ctx.musicManager.lock();
if (!manager) {
ctx.reply(ctx.tr(
"The music service is currently unavailable."));
return;
}
if (ctx.args.empty()) {
ctx.reply(
ctx.trf("Usage: remove <position>\nUse {}queue "
"to see track positions.",
ctx.prefix));
return;
}
uint32_t position = 0;
auto result =
std::from_chars(ctx.args.data(),
ctx.args.data() + ctx.args.size(),
position);
if (result.ec != std::errc() || position == 0) {
ctx.reply(
ctx.tr("Please provide a valid position number "
"(starting from 1)."));
return;
}
auto remResult = manager->removeFromQueue(
position - 1); // Convert to 0-based
if (!remResult) {
Void::Log::error(
"RemoveCommand", "{}",
std::format("Remove command failed: {}",
remResult.error().message));
if (remResult.error().code ==
Api::ErrorCode::NotFound) {
ctx.reply(ctx.tr(
"That position doesn't exist in the queue."));
} else {
ctx.reply(
ctx.tr("Couldn't remove that track. Please try "
"again."));
}
return;
}
ctx.reply(
ctx.trf("Removed track at position {}.", position));
} catch (const std::exception& e) {
Void::Log::error(
"RemoveCommand", "{}",
std::format("Remove command exception: {}", e.what()));
ctx.reply(
ctx.tr("Something went wrong. Please try again."));
}
}
std::string_view getDescription() const override
{
return "Removes a track from the queue by position.";
}
std::string_view getUsage() const override { return "<position>"; }
CommandCategory getCategory() const override
{
return CommandCategory::Queue;
}
std::vector<std::string_view> getAliases() const override
{
return {"rm", "delete", "del"};
}
};
} // namespace Echoion::Core