From f3a51071494ed1d093bd1d8a48469f02d3eb91dd Mon Sep 17 00:00:00 2001 From: garder500 Date: Mon, 5 May 2025 01:32:15 +0200 Subject: Refactor la fonction activity_type_from_string pour utiliser un tableau de paires au lieu de conditions if-else --- .vscode/settings.json | 99 --------------------------------------------------- bot/src/main.cpp | 26 ++++++-------- 2 files changed, 11 insertions(+), 114 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 42e44f8..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "cmake.sourceDirectory": "/home/exa/perso/bot-creator-api/bot", - "files.associations": { - "map": "cpp", - "__bit_reference": "cpp", - "__config": "cpp", - "__debug": "cpp", - "__errc": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__mutex_base": "cpp", - "__node_handle": "cpp", - "__split_buffer": "cpp", - "__threading_support": "cpp", - "__tree": "cpp", - "__verbose_abort": "cpp", - "any": "cpp", - "array": "cpp", - "atomic": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "charconv": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "complex": "cpp", - "condition_variable": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "exception": "cpp", - "coroutine": "cpp", - "forward_list": "cpp", - "fstream": "cpp", - "future": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "list": "cpp", - "locale": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "queue": "cpp", - "ratio": "cpp", - "set": "cpp", - "shared_mutex": "cpp", - "span": "cpp", - "sstream": "cpp", - "stack": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "thread": "cpp", - "tuple": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "valarray": "cpp", - "variant": "cpp", - "vector": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "chrono": "cpp", - "compare": "cpp", - "concepts": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "random": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "format": "cpp", - "stop_token": "cpp", - "codecvt": "cpp", - "numeric": "cpp", - "regex": "cpp", - "numbers": "cpp", - "ranges": "cpp", - "semaphore": "cpp", - "cinttypes": "cpp", - "unordered_set": "cpp" - } -} diff --git a/bot/src/main.cpp b/bot/src/main.cpp index 73bae00..4c5ecda 100644 --- a/bot/src/main.cpp +++ b/bot/src/main.cpp @@ -5,22 +5,18 @@ #include dpp::activity_type activity_type_from_string(const std::string &type) { - if (type == "playing") { - return dpp::activity_type::at_game; - } else if (type == "streaming") { - return dpp::activity_type::at_streaming; - } else if (type == "listening") { - return dpp::activity_type::at_listening; - } else if (type == "watching") { - return dpp::activity_type::at_watching; - } else if (type == "custom") { - return dpp::activity_type::at_custom; - } else if (type == "competing") { - return dpp::activity_type::at_competing; - } else { - return dpp::activity_type::at_game; // Default to "playing" if the type is - // unknown + static const std::pair type_map[] = { + {"playing", dpp::activity_type::at_game}, + {"streaming", dpp::activity_type::at_streaming}, + {"listening", dpp::activity_type::at_listening}, + {"watching", dpp::activity_type::at_watching}, + {"custom", dpp::activity_type::at_custom}, + {"competing", dpp::activity_type::at_competing} + }; + for (const auto& kv : type_map) { + if (kv.first == type) return kv.second; } + return dpp::activity_type::at_game; // default } int main(int argc, char *argv[]) { -- cgit v1.2.3