From 9b386ebe6a81412c43bc5705ec820941d21da2f5 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Fri, 11 Apr 2025 01:15:47 +0500 Subject: upd: support arrays in command responses --- bot/src/commands/lua.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'bot/src/commands') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 75261ec..571fdb5 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -378,7 +378,7 @@ namespace bot::command::lua { } } - std::string parse_lua_response(const sol::table &r, sol::object &res) { + Response parse_lua_response(const sol::table &r, sol::object &res) { if (res.get_type() == sol::type::function) { sol::function f = res.as(); sol::object o = f(r); @@ -389,9 +389,18 @@ namespace bot::command::lua { return {"🌑 " + std::to_string(res.as())}; } else if (res.get_type() == sol::type::boolean) { return {"🌑 " + 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()); + } + } + return {o}; } else { // should it be ResponseException? - return "Empty or unsupported response"; + return {"Empty or unsupported response"}; } } -- cgit v1.2.3