summaryrefslogtreecommitdiff
path: root/src/commands/command.cpp
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-04-21 17:20:38 +0500
committerilotterytea <iltsu@alright.party>2024-04-21 17:20:38 +0500
commit8c391504d160909753e6c6ee3186e0166b44c475 (patch)
tree43a95cf37ef9075d32a41ae8b7d924df68d845e9 /src/commands/command.cpp
parent6572077c73406cf6c353395aad13d493929a1596 (diff)
feat: use Request instead of Message + util for creating requests
Diffstat (limited to 'src/commands/command.cpp')
-rw-r--r--src/commands/command.cpp20
1 files changed, 11 insertions, 9 deletions
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 <iostream>
+#include <algorithm>
#include <memory>
#include <optional>
#include "../bundle.hpp"
#include "../modules/ping.hpp"
+#include "request.hpp"
namespace bot {
namespace command {
@@ -18,16 +19,17 @@ namespace bot {
}
std::optional<std::variant<std::vector<std::string>, std::string>>
- CommandLoader::run(
- const InstanceBundle &bundle,
- const irc::Message<irc::MessageType::Privmsg> &msg) const {
- for (const std::unique_ptr<Command> &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);
}
}
}