Migrate core infrastructure to VoidLibrary
This commit is contained in:
1 parent
53801f2b53
commit
2bdb63766d
65 files changed
+16109
-12011
No files matched your search
@@ -2,70 +2,81 @@
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core {
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class SkipCommand : 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;
|
||||
}
|
||||
class SkipCommand : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
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("Please provide a valid number (1 or more).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
void execute(const CommandContext& ctx) override
|
||||
{
|
||||
try {
|
||||
auto manager = ctx.musicManager.lock();
|
||||
if (!manager) {
|
||||
ctx.reply(
|
||||
"The music service is currently unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->skip(count);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Skip command failed: {}", result.error().message));
|
||||
|
||||
if (result.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply("No more tracks in the queue to skip to.");
|
||||
} else {
|
||||
ctx.reply("Couldn't skip. Please try again.");
|
||||
}
|
||||
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(
|
||||
"Please provide a valid number (1 or more).");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 1) {
|
||||
ctx.reply("Skipped to next track.");
|
||||
} else {
|
||||
ctx.reply(std::format("Skipped {} tracks.", count));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Skip command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
auto result = manager->skip(count);
|
||||
if (!result) {
|
||||
ECHOION_LOG_ERROR(std::format("Skip command failed: {}",
|
||||
result.error().message));
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Skips to the next track(s).";
|
||||
}
|
||||
if (result.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply(
|
||||
"No more tracks in the queue to skip to.");
|
||||
} else {
|
||||
ctx.reply("Couldn't skip. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "[count]";
|
||||
}
|
||||
if (count == 1) {
|
||||
ctx.reply("Skipped to next track.");
|
||||
} else {
|
||||
ctx.reply(std::format("Skipped {} tracks.", count));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(
|
||||
std::format("Skip command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Playback;
|
||||
}
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Skips to the next track(s).";
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"next", "n"};
|
||||
}
|
||||
};
|
||||
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
|
||||
Reference in new issue
Block a user