Delete the echoion Logger adapter (Logger.{hpp,cpp}) and the
ILogger/LoggerRegistry indirection. Core::installLogging() builds the
console + split-file Void::Logging::MultiLogger and installs it as the
process-wide Void::Log sink via Void::Log::make_sink (logSink_ owns it for
the process lifetime). The ~450 ECHOION_LOG_* call sites across EchoionCore
are rewritten to Void::Log::<level>("<Subsystem>", "{}", <expr>) with
per-file module tags (warning->warn, critical->fatal); the pre-formatted
message is passed as the single "{}" argument. Build green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
100 lines
2.4 KiB
C++
100 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "Command.hpp"
|
|
#include <Void/Log/Log.hpp>
|
|
#include <charconv>
|
|
#include <format>
|
|
|
|
namespace Echoion::Core
|
|
{
|
|
|
|
class MoveCommand : 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;
|
|
}
|
|
|
|
if (ctx.args.empty()) {
|
|
ctx.reply("Usage: move <from> <to>\nExample: move 5 1 "
|
|
"(moves track 5 to position 1)");
|
|
return;
|
|
}
|
|
|
|
// Parse arguments: from and to positions
|
|
uint32_t from = 0, to = 0;
|
|
|
|
auto spacePos = ctx.args.find(' ');
|
|
if (spacePos == std::string::npos) {
|
|
ctx.reply("Please provide both from and to positions.");
|
|
return;
|
|
}
|
|
|
|
auto result1 = std::from_chars(
|
|
ctx.args.data(), ctx.args.data() + spacePos, from);
|
|
auto result2 =
|
|
std::from_chars(ctx.args.data() + spacePos + 1,
|
|
ctx.args.data() + ctx.args.size(),
|
|
to);
|
|
|
|
if (result1.ec != std::errc() ||
|
|
result2.ec != std::errc() || from == 0 || to == 0) {
|
|
ctx.reply("Please provide valid position numbers "
|
|
"(starting from 1).");
|
|
return;
|
|
}
|
|
|
|
auto moveResult = manager->moveInQueue(
|
|
from - 1, to - 1); // Convert to 0-based
|
|
if (!moveResult) {
|
|
Void::Log::error("MoveCommand", "{}",
|
|
std::format("Move command failed: {}",
|
|
moveResult.error().message));
|
|
|
|
if (moveResult.error().code ==
|
|
Api::ErrorCode::NotFound) {
|
|
ctx.reply("One of those positions doesn't exist in "
|
|
"the queue.");
|
|
} else {
|
|
ctx.reply(
|
|
"Couldn't move that track. Please try again.");
|
|
}
|
|
return;
|
|
}
|
|
|
|
ctx.reply(std::format(
|
|
"Moved track from position {} to {}.", from, to));
|
|
} catch (const std::exception& e) {
|
|
Void::Log::error("MoveCommand", "{}",
|
|
std::format("Move command exception: {}", e.what()));
|
|
ctx.reply("Something went wrong. Please try again.");
|
|
}
|
|
}
|
|
|
|
std::string_view getDescription() const override
|
|
{
|
|
return "Moves a track to a different position in the queue.";
|
|
}
|
|
|
|
std::string_view getUsage() const override { return "<from> <to>"; }
|
|
|
|
CommandCategory getCategory() const override
|
|
{
|
|
return CommandCategory::Queue;
|
|
}
|
|
|
|
std::vector<std::string_view> getAliases() const override
|
|
{
|
|
return {"mv"};
|
|
}
|
|
};
|
|
|
|
} // namespace Echoion::Core
|