go into command manager
Signed-off-by: Aleksey Selihov <faumaray@gmail.com>
This commit is contained in:
1 parent
b94b634a87
commit
1153721546
19 files changed
+752
-229
No files matched your search
@@ -0,0 +1,73 @@
|
||||
#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 {}; }
|
||||
};
|
||||
Reference in new issue
Block a user