summaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-08 01:04:35 +0400
committerilotterytea <iltsu@alright.party>2025-04-08 01:04:35 +0400
commitf67badeab7089e85e53b20d6e20d41f641385aa8 (patch)
tree26941dcfe5bc4abc69801f3eedc209571f9f7619 /bot
parent3df43b800731f2c355c3bfef4d163df060ec1dcf (diff)
feat: twitch lua functions
Diffstat (limited to 'bot')
-rw-r--r--bot/src/commands/lua.cpp27
-rw-r--r--bot/src/commands/lua.hpp3
2 files changed, 30 insertions, 0 deletions
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 <algorithm>
#include <cmath>
#include <memory>
#include <nlohmann/json.hpp>
#include <sol/sol.hpp>
#include <stdexcept>
#include <string>
+#include <vector>
+#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<sol::state> 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<sol::state> state);
void add_time_library(std::shared_ptr<sol::state> state);
void add_json_library(std::shared_ptr<sol::state> state);
+ void add_twitch_library(std::shared_ptr<sol::state> state,
+ const Request &request,
+ const InstanceBundle &bundle);
void add_base_libraries(std::shared_ptr<sol::state> state);
}