From b4fca15aec26332c1315c8c3030169bbf342da3e Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 21 Apr 2024 03:25:12 +0500 Subject: feat: command loader --- src/commands/command.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/commands/command.cpp (limited to 'src/commands/command.cpp') diff --git a/src/commands/command.cpp b/src/commands/command.cpp new file mode 100644 index 0000000..b6852cc --- /dev/null +++ b/src/commands/command.cpp @@ -0,0 +1,30 @@ +#include "command.hpp" + +#include +#include +#include + +#include "../modules/ping.hpp" + +namespace bot { + namespace command { + CommandLoader::CommandLoader() { + this->add_command(std::make_unique()); + } + + void CommandLoader::add_command(std::unique_ptr command) { + this->commands.push_back(std::move(command)); + } + + std::optional, std::string>> + CommandLoader::run(const irc::Message &msg) { + for (const std::unique_ptr &command : this->commands) { + if (command->get_name() == msg.message) { + return command->run(msg); + } + } + + return std::nullopt; + } + } +} -- cgit v1.2.3