Files
EchoionCore/include/echoion/core/commands/Command.hpp
T
2026-02-03 05:07:15 +03:00

107 lines
2.4 KiB
C++

#pragma once
#include <echoion/api.hpp>
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>
#include <memory>
#include <functional>
#include "echoion/core/MusicManager.hpp"
namespace Echoion::Core {
class MusicManager;
enum class CommandCategory {
Music,
Queue,
Playback,
Utility,
Admin
};
inline std::string toString(CommandCategory category) {
switch (category) {
case CommandCategory::Music:
return "Music";
case CommandCategory::Queue:
return "Queue";
case CommandCategory::Playback:
return "Playback";
case CommandCategory::Utility:
return "Utility";
case CommandCategory::Admin:
return "Admin";
}
return "Utility";
}
/**
* @brief Context passed to every command execution.
* Wraps all dependencies required to perform an action.
*/
struct CommandContext {
uint64_t clientId = 0;
std::string prefix;
std::string args; // Arguments excluding the command name
std::string_view invokerName;
// Dependencies
std::weak_ptr<MusicManager> musicManager;
// Reply callback - set by CommandManager
std::function<void(std::string_view)> replyCallback;
// Helper to reply to the user
void reply(std::string_view message) const {
if (replyCallback) {
replyCallback(message);
}
}
};
/**
* @brief Interface that all commands must implement.
*/
class Command {
public:
virtual ~Command() = default;
/**
* @brief The logic of the command.
*/
virtual void execute(const CommandContext& ctx) = 0;
/**
* @brief Returns the description used for help generation.
*/
virtual std::string_view getDescription() const = 0;
/**
* @brief Returns usage syntax (e.g., "<url>").
*/
virtual std::string_view getUsage() const { return ""; }
/**
* @brief Returns the command category for grouping in help.
*/
virtual CommandCategory getCategory() const {
return CommandCategory::Utility;
}
/**
* @brief Returns aliases for this command.
*/
virtual std::vector<std::string_view> getAliases() const { return {}; }
/**
* @brief Returns whether this command requires admin privileges.
*/
virtual bool requiresAdmin() const { return false; }
};
using CommandPtr = std::shared_ptr<Command>;
} // namespace Echoion::Core