From d9427691e93a12f76a98b363aa424d4a2c40f262 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 17 Apr 2025 03:05:18 +0500 Subject: upd: include moon prefix only when using !lua and !luaimport --- bot/src/commands/lua.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'bot/src/commands') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 396a5a2..337551f 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -697,29 +697,32 @@ namespace bot::command::lua { } } - Response parse_lua_response(const sol::table &r, sol::object &res) { + Response parse_lua_response(const sol::table &r, sol::object &res, + bool moon_prefix = true) { + const std::string prefix = moon_prefix ? "🌑 " : ""; + if (res.get_type() == sol::type::function) { sol::function f = res.as(); sol::object o = f(r); return parse_lua_response(r, o); } else if (res.get_type() == sol::type::string) { - return {"🌑 " + res.as()}; + return {prefix + res.as()}; } else if (res.get_type() == sol::type::number) { - return {"🌑 " + std::to_string(res.as())}; + return {prefix + std::to_string(res.as())}; } else if (res.get_type() == sol::type::boolean) { - return {"🌑 " + std::to_string(res.as())}; + return {prefix + std::to_string(res.as())}; } else if (res.get_type() == sol::type::table) { sol::table t = res.as(); std::vector o; for (auto &kv : t) { if (kv.second.is()) { - o.push_back(kv.second.as()); + o.push_back(prefix + kv.second.as()); } } return {o}; } else { // should it be ResponseException? - return {"Empty or unsupported response"}; + return {prefix + "Empty or unsupported response"}; } } @@ -794,6 +797,6 @@ namespace bot::command::lua { const Request &request) const { sol::table r = request.as_lua_table(this->luaState); sol::object response = this->handle(r); - return parse_lua_response(r, response); + return parse_lua_response(r, response, false); } } \ No newline at end of file -- cgit v1.2.3