87 lines
2.0 KiB
C++
87 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include "Command.hpp"
|
|
#include <Void/Log/Log.hpp>
|
|
#include <charconv>
|
|
#include <format>
|
|
|
|
namespace Echoion::Core
|
|
{
|
|
|
|
class SkipCommand : 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;
|
|
}
|
|
|
|
uint32_t count = 1;
|
|
if (!ctx.args.empty()) {
|
|
auto result =
|
|
std::from_chars(ctx.args.data(),
|
|
ctx.args.data() + ctx.args.size(),
|
|
count);
|
|
if (result.ec != std::errc() || count == 0) {
|
|
ctx.reply(ctx.tr(
|
|
"Please provide a valid number (1 or more)."));
|
|
return;
|
|
}
|
|
}
|
|
|
|
auto result = manager->skip(count);
|
|
if (!result) {
|
|
Void::Log::error("SkipCommand", "{}",
|
|
std::format("Skip command failed: {}",
|
|
result.error().message));
|
|
|
|
if (result.error().code == Api::ErrorCode::NotFound) {
|
|
ctx.reply(ctx.tr(
|
|
"No more tracks in the queue to skip to."));
|
|
} else {
|
|
ctx.reply(
|
|
ctx.tr("Couldn't skip. Please try again."));
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (count == 1) {
|
|
ctx.reply(ctx.tr("Skipped to next track."));
|
|
} else {
|
|
ctx.reply(ctx.trf("Skipped {} tracks.", count));
|
|
}
|
|
} catch (const std::exception& e) {
|
|
Void::Log::error(
|
|
"SkipCommand", "{}",
|
|
std::format("Skip command exception: {}", e.what()));
|
|
ctx.reply(
|
|
ctx.tr("Something went wrong. Please try again."));
|
|
}
|
|
}
|
|
|
|
std::string_view getDescription() const override
|
|
{
|
|
return "Skips to the next track(s).";
|
|
}
|
|
|
|
std::string_view getUsage() const override { return "[count]"; }
|
|
|
|
CommandCategory getCategory() const override
|
|
{
|
|
return CommandCategory::Playback;
|
|
}
|
|
|
|
std::vector<std::string_view> getAliases() const override
|
|
{
|
|
return {"next", "n"};
|
|
}
|
|
};
|
|
|
|
} // namespace Echoion::Core
|