74 lines
1.6 KiB
C++
74 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string_view>
|
|
#include <teamspeak/public_definitions.h>
|
|
#include <ts3_functions.h>
|
|
#include <ts6bot/MusicManager.hpp>
|
|
|
|
enum class CommandCategory { Music, Session, Utility };
|
|
|
|
inline std::string to_string(CommandCategory category)
|
|
{
|
|
switch (category) {
|
|
|
|
case CommandCategory::Music:
|
|
return "Music";
|
|
case CommandCategory::Session:
|
|
return "Session";
|
|
case CommandCategory::Utility:
|
|
return "Utility";
|
|
}
|
|
return "Utility";
|
|
}
|
|
/**
|
|
* @brief Context passed to every command execution.
|
|
* Wraps all dependencies required to perform an action.
|
|
*/
|
|
struct CommandContext {
|
|
std::uint64_t serverConnectionHandlerID;
|
|
anyID clientID;
|
|
std::string args; // Arguments excluding the command name
|
|
std::string_view invokerName;
|
|
|
|
// Dependencies
|
|
std::shared_ptr<TS3Functions> ts3;
|
|
std::weak_ptr<MusicManager> musicManager; // Non-owning reference
|
|
|
|
// Helper to reply to the user
|
|
void reply(std::string_view message) const;
|
|
};
|
|
|
|
/**
|
|
* @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 = 0;
|
|
|
|
virtual CommandCategory getCategory() const
|
|
{
|
|
return CommandCategory::Utility;
|
|
}
|
|
|
|
// Commands can now define their own aliases for the help menu
|
|
virtual std::vector<std::string_view> getAliases() const { return {}; }
|
|
};
|