diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-17 03:05:18 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-17 03:05:18 +0500 |
| commit | d9427691e93a12f76a98b363aa424d4a2c40f262 (patch) | |
| tree | 003040a75a766b7998318e70e7644954389e85f7 /bot/src | |
| parent | 760f4d680cea948bd19b072ef8d4a977bb4cf51f (diff) | |
upd: include moon prefix only when using !lua and !luaimport
Diffstat (limited to 'bot/src')
| -rw-r--r-- | bot/src/commands/lua.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
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::function>(); sol::object o = f(r); return parse_lua_response(r, o); } else if (res.get_type() == sol::type::string) { - return {"🌑 " + res.as<std::string>()}; + return {prefix + res.as<std::string>()}; } else if (res.get_type() == sol::type::number) { - return {"🌑 " + std::to_string(res.as<double>())}; + return {prefix + std::to_string(res.as<double>())}; } else if (res.get_type() == sol::type::boolean) { - return {"🌑 " + std::to_string(res.as<bool>())}; + return {prefix + std::to_string(res.as<bool>())}; } else if (res.get_type() == sol::type::table) { sol::table t = res.as<sol::table>(); std::vector<std::string> o; for (auto &kv : t) { if (kv.second.is<std::string>()) { - o.push_back(kv.second.as<std::string>()); + o.push_back(prefix + kv.second.as<std::string>()); } } 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 |
