From 8c391504d160909753e6c6ee3186e0166b44c475 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 21 Apr 2024 17:20:38 +0500 Subject: feat: use Request instead of Message + util for creating requests --- src/commands/command.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/commands/command.cpp') diff --git a/src/commands/command.cpp b/src/commands/command.cpp index 9d6ec6a..bf482f5 100644 --- a/src/commands/command.cpp +++ b/src/commands/command.cpp @@ -1,11 +1,12 @@ #include "command.hpp" -#include +#include #include #include #include "../bundle.hpp" #include "../modules/ping.hpp" +#include "request.hpp" namespace bot { namespace command { @@ -18,16 +19,17 @@ namespace bot { } std::optional, std::string>> - CommandLoader::run( - const InstanceBundle &bundle, - const irc::Message &msg) const { - for (const std::unique_ptr &command : this->commands) { - if (command->get_name() == msg.message) { - return command->run(bundle, msg); - } + CommandLoader::run(const InstanceBundle &bundle, + const Request &request) const { + auto command = std::find_if( + this->commands.begin(), this->commands.end(), + [&](const auto &x) { return x->get_name() == request.command_id; }); + + if (command == this->commands.end()) { + return std::nullopt; } - return std::nullopt; + return (*command)->run(bundle, request); } } } -- cgit v1.2.3