From cfadebfab40be3780aa2b583b3fbad415cdaca93 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 2 Apr 2024 22:46:15 +0300 Subject: [PATCH] tg_cli: reduce if-else chain length. --- td/telegram/cli.cpp | 56 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f8a344b5f..7a293dd53 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2421,7 +2421,7 @@ class CliClient final : public Actor { string args; std::tie(op, args) = split(cmd); - const int32 OP_BLOCK_COUNT = 10; + const int32 OP_BLOCK_COUNT = 19; int32 op_not_found_count = 0; if (op == "gas") { @@ -2598,7 +2598,11 @@ class CliClient final : public Actor { send_request(td_api::make_object(args)); } else if (op == "rpncc") { send_request(td_api::make_object()); - } else if (op == "rpr") { + } else { + op_not_found_count++; + } + + if (op == "rpr") { send_request(td_api::make_object()); } else if (op == "cprc") { string recovery_code = args; @@ -3127,7 +3131,11 @@ class CliClient final : public Actor { send_request(td_api::make_object(language_code, std::move(str))); } else if (op == "dlp") { send_request(td_api::make_object(args)); - } else if (op == "on" || op == "off") { + } else { + op_not_found_count++; + } + + if (op == "on" || op == "off") { send_request(td_api::make_object("online", td_api::make_object(op == "on"))); } else if (op == "go") { @@ -3403,7 +3411,11 @@ class CliClient final : public Actor { FileId file_id; get_args(args, file_id); send_request(td_api::make_object(file_id)); - } else if (op == "storage") { + } else { + op_not_found_count++; + } + + if (op == "storage") { int32 chat_limit; get_args(args, chat_limit); send_request(td_api::make_object(chat_limit)); @@ -4149,7 +4161,11 @@ class CliClient final : public Actor { GroupCallId group_call_id; get_args(args, group_call_id); send_request(td_api::make_object(group_call_id)); - } else if (op == "rpcil") { + } else { + op_not_found_count++; + } + + if (op == "rpcil") { ChatId chat_id; get_args(args, chat_id); send_request(td_api::make_object(chat_id)); @@ -4641,7 +4657,11 @@ class CliClient final : public Actor { UserId user_id; get_args(args, chat_id, user_id); send_request(td_api::make_object(chat_id, user_id)); - } else if (op == "gamb") { + } else { + op_not_found_count++; + } + + if (op == "gamb") { UserId user_id; get_args(args, user_id); send_request(td_api::make_object(user_id)); @@ -4912,7 +4932,11 @@ class CliClient final : public Actor { get_args(args, chat_id, message_id, date); send_request(td_api::make_object(chat_id, message_id, as_message_scheduling_state(date))); - } else if (op == "cqrsn") { + } else { + op_not_found_count++; + } + + if (op == "cqrsn") { execute(td_api::make_object(args)); } else if (op == "lqrs") { send_request(td_api::make_object()); @@ -5465,7 +5489,11 @@ class CliClient final : public Actor { bool force; get_args(args, supergroup_id, force); send_request(td_api::make_object(as_supergroup_id(supergroup_id), force)); - } else if (op == "gcltac") { + } else { + op_not_found_count++; + } + + if (op == "gcltac") { ChatId chat_id; get_args(args, chat_id); send_request(td_api::make_object(chat_id)); @@ -5964,7 +5992,11 @@ class CliClient final : public Actor { get_args(args, supergroup_id, join_by_request); send_request( td_api::make_object(as_supergroup_id(supergroup_id), join_by_request)); - } else if (op == "scar") { + } else { + op_not_found_count++; + } + + if (op == "scar") { ChatId chat_id; string available_reactions; get_args(args, chat_id, available_reactions); @@ -6179,7 +6211,11 @@ class CliClient final : public Actor { UserId bot_user_id; get_args(args, bot_user_id); send_request(td_api::make_object(bot_user_id)); - } else if (op == "swacr") { + } else { + op_not_found_count++; + } + + if (op == "swacr") { UserId bot_user_id; string method; string parameters;