diff options
| author | ilotterytea <iltsu@alright.party> | 2025-07-22 23:56:44 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-07-22 23:56:44 +0500 |
| commit | 6da71eb3e118dbd6f55830922f6ef98cd6960147 (patch) | |
| tree | 0e5408450c4bf2061e9c8d83e8a622acab25c51f | |
| parent | 84aebba223b6a8f9eb2d1272c3ed2083d561f2b9 (diff) | |
feat: RSS library for Lua
| -rw-r--r-- | bot/src/commands/lua.cpp | 14 | ||||
| -rw-r--r-- | bot/src/commands/lua.hpp | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/bot/src/commands/lua.cpp b/bot/src/commands/lua.cpp index 460fe25..b7173ab 100644 --- a/bot/src/commands/lua.cpp +++ b/bot/src/commands/lua.cpp @@ -13,6 +13,7 @@ #include <iomanip> #include <memory> #include <nlohmann/json.hpp> +#include <optional> #include <sol/sol.hpp> #include <sstream> #include <stdexcept> @@ -31,6 +32,7 @@ #include "cpr/multipart.h" #include "cpr/response.h" #include "database.hpp" +#include "rss.hpp" #include "schemas/channel.hpp" #include "schemas/stream.hpp" #include "schemas/user.hpp" @@ -626,6 +628,17 @@ namespace bot::command::lua { }); } + void add_rss_library(std::shared_ptr<sol::state> state) { + state->set_function("rss_get", [state](const std::string &url) { + std::optional<RSSChannel> channel = bot::get_rss_channel(url); + if (!channel.has_value()) { + return sol::make_object(*state, sol::lua_nil); + } + + return sol::make_object(*state, channel->as_lua_table(state)); + }); + } + void add_base_libraries(std::shared_ptr<sol::state> state) { add_bot_library(state); add_time_library(state); @@ -633,6 +646,7 @@ namespace bot::command::lua { add_net_library(state); add_string_library(state); add_array_library(state); + add_rss_library(state); } void add_chat_libraries(std::shared_ptr<sol::state> state, diff --git a/bot/src/commands/lua.hpp b/bot/src/commands/lua.hpp index 1e0cd4b..27cc142 100644 --- a/bot/src/commands/lua.hpp +++ b/bot/src/commands/lua.hpp @@ -43,6 +43,8 @@ namespace bot::command::lua { const Request &request, const Configuration &cfg, const std::string &lua_id); + void add_rss_library(std::shared_ptr<sol::state> state); + void add_base_libraries(std::shared_ptr<sol::state> state); void add_chat_libraries(std::shared_ptr<sol::state> state, const Request &request, |
