summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands/command.hpp3
-rw-r--r--src/commands/request_util.cpp13
2 files changed, 13 insertions, 3 deletions
diff --git a/src/commands/command.hpp b/src/commands/command.hpp
index 922858e..345b821 100644
--- a/src/commands/command.hpp
+++ b/src/commands/command.hpp
@@ -20,6 +20,9 @@ namespace bot {
return schemas::PermissionLevel::USER;
}
virtual int get_delay_seconds() const { return 5; }
+ virtual std::vector<std::string> get_subcommand_ids() const {
+ return {};
+ }
};
class CommandLoader {
diff --git a/src/commands/request_util.cpp b/src/commands/request_util.cpp
index 8ac2471..b51abee 100644
--- a/src/commands/request_util.cpp
+++ b/src/commands/request_util.cpp
@@ -32,12 +32,12 @@ namespace bot::command {
command_id =
command_id.substr(DEFAULT_PREFIX.length(), command_id.length());
- bool found = std::any_of(
+ auto cmd = std::find_if(
command_loader.get_commands().begin(),
command_loader.get_commands().end(),
[&](const auto &command) { return command->get_name() == command_id; });
- if (!found) {
+ if (cmd == command_loader.get_commands().end()) {
return std::nullopt;
}
@@ -177,7 +177,14 @@ namespace bot::command {
if (subcommand_id->empty()) {
subcommand_id = std::nullopt;
}
- parts.erase(parts.begin());
+
+ auto subcommand_ids = (*cmd)->get_subcommand_ids();
+
+ if (subcommand_id != std::nullopt &&
+ std::any_of(subcommand_ids.begin(), subcommand_ids.end(),
+ [&](const auto &x) { return x == subcommand_id; })) {
+ parts.erase(parts.begin());
+ }
std::optional<std::string> message = utils::string::join_vector(parts, ' ');