From d1fcac7411bd0a686c3ccaa7416d98dc197c4e59 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 6 Apr 2025 19:29:29 +0400 Subject: feat: lua execution error --- bot/src/commands/response_error.hpp | 15 +++++++++++---- bot/src/handlers.cpp | 9 ++------- bot/src/localization/line_id.cpp | 2 ++ bot/src/localization/line_id.hpp | 1 + localization/english.json | 1 + localization/russian.json | 1 + 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/bot/src/commands/response_error.hpp b/bot/src/commands/response_error.hpp index ae2c3ee..b89d38e 100644 --- a/bot/src/commands/response_error.hpp +++ b/bot/src/commands/response_error.hpp @@ -7,6 +7,7 @@ #include #include "command.hpp" +#include "localization/line_id.hpp" #include "request.hpp" namespace bot { @@ -23,7 +24,9 @@ namespace bot { EXTERNAL_API_ERROR, INSUFFICIENT_RIGHTS, - ILLEGAL_COMMAND + ILLEGAL_COMMAND, + + LUA_EXECUTION_ERROR }; template @@ -31,9 +34,10 @@ namespace bot { template class ResponseException< - T, typename std::enable_if< - T == INCORRECT_ARGUMENT || T == INCOMPATIBLE_NAME || - T == NAMESAKE_CREATION || T == NOT_FOUND>::type> + T, typename std::enable_if::type> : public std::exception { public: ResponseException(const command::Request &request, @@ -58,6 +62,9 @@ namespace bot { case NOT_FOUND: line_id = loc::LineId::ErrorNotFound; break; + case LUA_EXECUTION_ERROR: + line_id = loc::LineId::ErrorLuaExecutionError; + break; default: line_id = loc::LineId::ErrorSomethingWentWrong; break; diff --git a/bot/src/handlers.cpp b/bot/src/handlers.cpp index fe8c73c..42e1090 100644 --- a/bot/src/handlers.cpp +++ b/bot/src/handlers.cpp @@ -12,6 +12,7 @@ #include "commands/command.hpp" #include "commands/request.hpp" #include "commands/request_util.hpp" +#include "commands/response_error.hpp" #include "constants.hpp" #include "cpr/api.h" #include "cpr/multipart.h" @@ -55,13 +56,7 @@ namespace bot::handlers { return; } } catch (const std::exception &e) { - std::string line = - bundle.localization - .get_formatted_line(request.value(), - loc::LineId::ErrorSomethingWentWrong, {}) - .value(); - - bundle.irc_client.say(message.source.login, line); + bundle.irc_client.say(message.source.login, e.what()); log::error("PrivMsg/" + request->command_id, e.what()); } } diff --git a/bot/src/localization/line_id.cpp b/bot/src/localization/line_id.cpp index 7f17378..7382d91 100644 --- a/bot/src/localization/line_id.cpp +++ b/bot/src/localization/line_id.cpp @@ -48,6 +48,8 @@ namespace bot { return LineId::ErrorInsufficientRights; } else if (str == "error.illegal_command") { return LineId::ErrorIllegalCommand; + } else if (str == "error.lua_execution_error") { + return LineId::ErrorLuaExecutionError; } else if (str == "event.on") { diff --git a/bot/src/localization/line_id.hpp b/bot/src/localization/line_id.hpp index e9b90c0..bc84074 100644 --- a/bot/src/localization/line_id.hpp +++ b/bot/src/localization/line_id.hpp @@ -26,6 +26,7 @@ namespace bot { ErrorExternalAPIError, ErrorInsufficientRights, ErrorIllegalCommand, + ErrorLuaExecutionError, PingResponse, diff --git a/localization/english.json b/localization/english.json index c7cc035..c471ada 100644 --- a/localization/english.json +++ b/localization/english.json @@ -19,6 +19,7 @@ "error.external_api_error": "External API error (%s%s)", "error.insufficient_rights": "Insufficient rights", "error.illegal_command": "Command not available", + "error.lua_execution_error": "Lua execution error: %s", "ping.response": "{sender.alias_name}: funnywhitecat Pong! %s Uptime: %s · Used memory: %sMB", diff --git a/localization/russian.json b/localization/russian.json index 3790aea..4be5345 100644 --- a/localization/russian.json +++ b/localization/russian.json @@ -19,6 +19,7 @@ "error.external_api_error": "Ошибка стороннего API (%s%s)", "error.insufficient_rights": "Недостаточно прав", "error.illegal_command": "Команда недоступна", + "error.lua_execution_error": "Lua execution error: %s", "ping.response": "{sender.alias_name}: funnywhitecat Понг! %s Время сессии: %s · ОЗУ: %sМБ", -- cgit v1.2.3