From f67badeab7089e85e53b20d6e20d41f641385aa8 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 8 Apr 2025 01:04:35 +0400 Subject: feat: twitch lua functions --- bot/src/commands/lua.cpp | 27 +++++++++++++++++++++++++++ bot/src/commands/lua.hpp | 3 +++ 2 files changed, 30 insertions(+) (limited to 'bot/src') diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index e362a37..f11bc9e 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -1,12 +1,15 @@ #include "commands/lua.hpp" +#include #include #include #include #include #include #include +#include +#include "api/twitch/schemas/user.hpp" #include "bundle.hpp" #include "commands/request.hpp" #include "commands/response.hpp" @@ -166,6 +169,30 @@ namespace bot::command::lua { add_time_library(state); add_json_library(state); } + + void add_twitch_library(std::shared_ptr state, + const Request &request, + const InstanceBundle &bundle) { + // TODO: ratelimits + state->set_function("twitch_get_chatters", [state, &request, &bundle]() { + auto chatters = bundle.helix_client.get_chatters( + request.channel.get_alias_id(), bundle.irc_client.get_bot_id()); + + sol::table o = state->create_table(); + + std::for_each(chatters.begin(), chatters.end(), + [state, &o](const api::twitch::schemas::User &x) { + sol::table u = state->create_table(); + + u["id"] = x.id; + u["login"] = x.login; + + o.add(u); + }); + + return o; + }); + } } std::string parse_lua_response(const sol::table &r, sol::object &res) { diff --git a/bot/src/commands/lua.hpp b/bot/src/commands/lua.hpp index 87159cc..28071b6 100644 --- a/bot/src/commands/lua.hpp +++ b/bot/src/commands/lua.hpp @@ -19,6 +19,9 @@ namespace bot::command::lua { void add_bot_library(std::shared_ptr state); void add_time_library(std::shared_ptr state); void add_json_library(std::shared_ptr state); + void add_twitch_library(std::shared_ptr state, + const Request &request, + const InstanceBundle &bundle); void add_base_libraries(std::shared_ptr state); } -- cgit v1.2.3