diff options
| author | ilotterytea <iltsu@alright.party> | 2024-05-02 02:05:33 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-05-02 02:05:33 +0500 |
| commit | 42e4bf7bb1104dffa46ae5bcb102e4ced69d6bbf (patch) | |
| tree | 536b716b1f4ec5a42a31e84ca4ac3f43dfcde4dc /src | |
| parent | 673f55a39e5e7626ca29becf60ba161f264a8ad1 (diff) | |
feat: subcommand id check
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands/command.hpp | 3 | ||||
| -rw-r--r-- | src/commands/request_util.cpp | 13 |
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, ' '); |
