58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <Command/Interface.hpp>
|
|
#include <PluginInterface.hpp>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
class CommandManager
|
|
{
|
|
public:
|
|
|
|
explicit CommandManager(std::shared_ptr<TS3Functions> ts3);
|
|
|
|
/**
|
|
* @brief Registers a command class.
|
|
* @tparam T The command class (must inherit ICommand).
|
|
* @param names List of triggers (e.g., {"play", "p"}).
|
|
*/
|
|
template <typename T>
|
|
void registerCommand(const std::string& primaryName)
|
|
{
|
|
auto cmd = std::make_shared<T>();
|
|
|
|
// Register primary
|
|
m_commands[primaryName] = cmd;
|
|
m_uniqueCommands.push_back({primaryName, cmd});
|
|
|
|
// Register aliases automatically from the class itself
|
|
for (auto alias : cmd->getAliases()) {
|
|
m_commands[std::string(alias)] = cmd;
|
|
}
|
|
}
|
|
|
|
bool dispatch(uint64 scHandlerID, anyID clientID,
|
|
std::string_view invokerName, std::string_view message,
|
|
std::weak_ptr<MusicManager> musicManager);
|
|
|
|
private:
|
|
|
|
struct CommandEntry {
|
|
std::string primaryName;
|
|
std::shared_ptr<Command> instance;
|
|
};
|
|
void registerAllDefaults();
|
|
|
|
// Internal Help Command (defined inside manager to access registry)
|
|
class HelpCommand;
|
|
|
|
std::shared_ptr<TS3Functions> m_ts3;
|
|
|
|
// Map for fast lookup: "play" -> PlayCommand*
|
|
std::unordered_map<std::string, std::shared_ptr<Command>> m_commands;
|
|
|
|
// List for generating help: {"play", PlayCommand*}
|
|
std::vector<CommandEntry> m_uniqueCommands;
|
|
};
|