Initial commit
This commit is contained in:
commit
a583c17916
56 files changed
+11025
No files matched your search
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include "Command.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <format>
|
||||
#include <charconv>
|
||||
|
||||
namespace Echoion::Core {
|
||||
|
||||
class SelectCommand : 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: select <number>\nSelect a track from your last search results.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse index
|
||||
uint32_t index = 0;
|
||||
auto result = std::from_chars(ctx.args.data(),
|
||||
ctx.args.data() + ctx.args.size(),
|
||||
index);
|
||||
if (result.ec != std::errc() || index == 0) {
|
||||
ctx.reply("Please provide a valid number (1, 2, 3, etc.).");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string invokerName(ctx.invokerName);
|
||||
auto selectResult = manager->selectSearchResult(ctx.clientId, index, invokerName);
|
||||
|
||||
if (!selectResult) {
|
||||
ECHOION_LOG_ERROR(std::format("Select failed for client {} index {}: {}",
|
||||
ctx.clientId, index, selectResult.error().message));
|
||||
|
||||
if (selectResult.error().code == Api::ErrorCode::NotFound) {
|
||||
ctx.reply("No search results found. Use [prefix]play <query> to search first.");
|
||||
} else {
|
||||
ctx.reply("Couldn't select that track. Please try again.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.reply(*selectResult);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
ECHOION_LOG_ERROR(std::format("Select command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override {
|
||||
return "Selects a track from your search results.";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override {
|
||||
return "<number>";
|
||||
}
|
||||
|
||||
CommandCategory getCategory() const override {
|
||||
return CommandCategory::Music;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override {
|
||||
return {"sel", "pick", "choose"};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
Reference in new issue
Block a user