summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-10 21:56:17 +0500
committerilotterytea <iltsu@alright.party>2025-04-10 21:56:17 +0500
commitf649ead41180d3fc2c24480c843b0cf4bb636f97 (patch)
treeeb74c3a8ce10254aba388a2856abbc6ec4f3f43b
parent0487cb46d45ebb23161f9ef8f3135c04a5010b59 (diff)
feat: get json value by string path (new lua function)
-rw-r--r--bot/src/commands/lua.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp
index b8d0dee..589fd27 100644
--- a/bot/src/commands/lua.cpp
+++ b/bot/src/commands/lua.cpp
@@ -180,6 +180,18 @@ namespace bot::command::lua {
state->set_function("json_stringify", [](const sol::object &o) {
return lua_to_json(o).dump();
});
+
+ state->set_function("json_get_value", [state](const sol::object &body,
+ const std::string &path) {
+ std::vector<std::string> parts = utils::string::split_text(path, '.');
+ nlohmann::json o = lua_to_json(body);
+
+ for (const std::string &path : parts) {
+ o = o[path];
+ }
+
+ return parse_json_object(state, o);
+ });
}
void add_net_library(std::shared_ptr<sol::state> state) {