From 42e4bf7bb1104dffa46ae5bcb102e4ced69d6bbf Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 2 May 2024 02:05:33 +0500 Subject: feat: subcommand id check --- src/commands/request_util.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/commands/request_util.cpp') 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 message = utils::string::join_vector(parts, ' '); -- cgit v1.2.3