Files
EchoionCore/include/echoion/core/commands/VolumeCommand.hpp
T
faumarayandClaude Opus 4.8 2d7651c308 Route all logging through the Void::Log facade
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>
2026-06-23 14:10:06 +03:00

102 lines
2.4 KiB
C++

#pragma once
#include "Command.hpp"
#include <Void/Log/Log.hpp>
#include <charconv>
#include <format>
namespace Echoion::Core
{
class VolumeCommand : 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()) {
// Show current volume
auto state = manager->getPlaybackState();
if (state) {
ctx.reply(std::format(
"Current volume: {}%",
static_cast<int>(state->volume * 100)));
} else {
ctx.reply("Unable to get current volume.");
}
return;
}
// Parse volume (0-100)
int volumePercent = 0;
auto result =
std::from_chars(ctx.args.data(),
ctx.args.data() + ctx.args.size(),
volumePercent);
if (result.ec != std::errc()) {
ctx.reply("Please provide a valid number (0-100).");
return;
}
if (volumePercent < 0 || volumePercent > 100) {
ctx.reply("Volume must be between 0 and 100.");
return;
}
float volume = volumePercent / 100.0f;
auto volResult = manager->setVolume(volume);
if (!volResult) {
Void::Log::error("VolumeCommand", "{}",
std::format("Volume command failed: {}",
volResult.error().message));
ctx.reply("Couldn't change volume. Please try again.");
return;
}
// Visual volume indicator
std::string indicator;
int bars = volumePercent / 10;
for (int i = 0; i < 10; ++i) {
indicator +=
(i < bars)
? "\xe2\x96\x88"
: "\xe2\x96\x91"; // Full block / Light shade
}
ctx.reply(std::format(
"Volume: {}% {}", volumePercent, indicator));
} catch (const std::exception& e) {
Void::Log::error("VolumeCommand", "{}",
std::format("Volume command exception: {}", e.what()));
ctx.reply("Something went wrong. Please try again.");
}
}
std::string_view getDescription() const override
{
return "Sets or shows the playback volume.";
}
std::string_view getUsage() const override { return "[0-100]"; }
CommandCategory getCategory() const override
{
return CommandCategory::Playback;
}
std::vector<std::string_view> getAliases() const override
{
return {"vol", "v"};
}
};
} // namespace Echoion::Core