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>
149 lines
3.8 KiB
C++
149 lines
3.8 KiB
C++
#pragma once
|
|
|
|
#include "Command.hpp"
|
|
#include <Void/Log/Log.hpp>
|
|
#include <charconv>
|
|
#include <chrono>
|
|
#include <format>
|
|
|
|
namespace Echoion::Core
|
|
{
|
|
|
|
class SeekCommand : 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: seek <+/-seconds>\nExamples:\n seek +30 "
|
|
"(skip forward 30s)\n seek -10 (skip back 10s)\n "
|
|
"seek 60 (jump to 1 minute mark)");
|
|
return;
|
|
}
|
|
|
|
// Parse the seek argument (supports +30, -10, or absolute
|
|
// 60)
|
|
std::string_view arg = ctx.args;
|
|
bool relative = false;
|
|
bool forward = true;
|
|
|
|
if (arg.starts_with('+')) {
|
|
relative = true;
|
|
forward = true;
|
|
arg = arg.substr(1);
|
|
} else if (arg.starts_with('-')) {
|
|
relative = true;
|
|
forward = false;
|
|
arg = arg.substr(1);
|
|
}
|
|
|
|
int seconds = 0;
|
|
auto parseResult = std::from_chars(
|
|
arg.data(), arg.data() + arg.size(), seconds);
|
|
if (parseResult.ec != std::errc() || seconds < 0) {
|
|
ctx.reply(
|
|
"Please provide a valid number of "
|
|
"seconds.\nExamples: seek +30, seek -10, seek 60");
|
|
return;
|
|
}
|
|
|
|
std::chrono::milliseconds targetPosition;
|
|
std::string positionStr;
|
|
|
|
if (relative) {
|
|
// Get current position from playback state
|
|
auto state = manager->getPlaybackState();
|
|
if (!state) {
|
|
ctx.reply(
|
|
"Unable to get current playback position.");
|
|
return;
|
|
}
|
|
|
|
auto currentPos = state->position;
|
|
if (forward) {
|
|
targetPosition =
|
|
currentPos + std::chrono::seconds(seconds);
|
|
positionStr = std::format("+{}s", seconds);
|
|
} else {
|
|
// Seek backward
|
|
if (currentPos.count() < seconds * 1000) {
|
|
targetPosition = std::chrono::milliseconds(0);
|
|
} else {
|
|
targetPosition =
|
|
currentPos - std::chrono::seconds(seconds);
|
|
}
|
|
positionStr = std::format("-{}s", seconds);
|
|
}
|
|
} else {
|
|
// Absolute seek (legacy behavior)
|
|
targetPosition = std::chrono::seconds(seconds);
|
|
auto mins = seconds / 60;
|
|
auto secs = seconds % 60;
|
|
positionStr = std::format("{}:{:02}", mins, secs);
|
|
}
|
|
|
|
auto result = manager->seek(targetPosition);
|
|
if (!result) {
|
|
Void::Log::error("SeekCommand", "{}", std::format("Seek command failed: {}",
|
|
result.error().message));
|
|
|
|
if (result.error().code ==
|
|
Api::ErrorCode::InvalidArgument) {
|
|
ctx.reply("Nothing is playing right now.");
|
|
} else if (result.error().code ==
|
|
Api::ErrorCode::NotSupported) {
|
|
ctx.reply("This track doesn't support seeking.");
|
|
} else {
|
|
ctx.reply("Couldn't seek. Please try again.");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (relative) {
|
|
ctx.reply(std::format(
|
|
"Seeked {} from current position.", positionStr));
|
|
} else {
|
|
ctx.reply(
|
|
std::format("Seeked to position {}.", positionStr));
|
|
}
|
|
} catch (const std::exception& e) {
|
|
Void::Log::error("SeekCommand", "{}",
|
|
std::format("Seek command exception: {}", e.what()));
|
|
ctx.reply("Something went wrong. Please try again.");
|
|
}
|
|
}
|
|
|
|
std::string_view getDescription() const override
|
|
{
|
|
return "Seeks to a position in the current track. Use +seconds "
|
|
"to skip forward, -seconds to skip backward.";
|
|
}
|
|
|
|
std::string_view getUsage() const override
|
|
{
|
|
return "<+/-seconds>";
|
|
}
|
|
|
|
CommandCategory getCategory() const override
|
|
{
|
|
return CommandCategory::Playback;
|
|
}
|
|
|
|
std::vector<std::string_view> getAliases() const override
|
|
{
|
|
return {"jump"};
|
|
}
|
|
};
|
|
|
|
} // namespace Echoion::Core
|