From 8a5c0ccec6a7d03525ba4e788c47f2c3c82b0238 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 12 Apr 2025 16:53:03 +0500 Subject: feat: bot_username() function --- bot/src/commands/command.cpp | 1 + bot/src/commands/lua.cpp | 9 +++++++++ bot/src/commands/lua.hpp | 2 ++ 3 files changed, 12 insertions(+) (limited to 'bot/src/commands') diff --git a/bot/src/commands/command.cpp b/bot/src/commands/command.cpp index 4ec8e59..ba4edbe 100644 --- a/bot/src/commands/command.cpp +++ b/bot/src/commands/command.cpp @@ -89,6 +89,7 @@ namespace bot { std::optional CommandLoader::run(const InstanceBundle &bundle, const Request &request) { + lua::library::add_bot_library(this->luaState, bundle); lua::library::add_twitch_library(this->luaState, request, bundle); auto command = std::find_if( diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 571fdb5..96a9a68 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -76,6 +76,15 @@ namespace bot::command::lua { }); } + void add_bot_library(std::shared_ptr state, + const InstanceBundle &bundle) { + state->set_function("bot_username", [&bundle]() { + return bundle.irc_client.get_bot_username(); + }); + + add_bot_library(state); + } + void add_time_library(std::shared_ptr state) { state->set_function("time_current", []() { return static_cast( diff --git a/bot/src/commands/lua.hpp b/bot/src/commands/lua.hpp index 9853b27..0adb75e 100644 --- a/bot/src/commands/lua.hpp +++ b/bot/src/commands/lua.hpp @@ -17,6 +17,8 @@ void print_lua_object_type(const sol::object &obj); namespace bot::command::lua { namespace library { void add_bot_library(std::shared_ptr state); + void add_bot_library(std::shared_ptr state, + const InstanceBundle &bundle); void add_time_library(std::shared_ptr state); void add_json_library(std::shared_ptr state); void add_twitch_library(std::shared_ptr state, -- cgit v1.2.3