From 0d36a1ee88fb7aedf5b33af7ac95140b002c5a64 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Mon, 1 Dec 2025 16:50:39 +0500 Subject: feat: rss timeout --- bot/src/config.cpp | 27 +++++++++++++++++++-------- bot/src/config.hpp | 9 +++++++-- bot/src/rss.cpp | 7 ++++--- 3 files changed, 30 insertions(+), 13 deletions(-) (limited to 'bot') diff --git a/bot/src/config.cpp b/bot/src/config.cpp index 4e4b71d..6cd8cf1 100644 --- a/bot/src/config.cpp +++ b/bot/src/config.cpp @@ -65,18 +65,23 @@ namespace bot { } else { url["randompost"] = sol::lua_nil; } - if (this->url.rssbridge.has_value()) { - url["rssbridge"] = this->url.rssbridge.value(); + o["url"] = url; + + sol::table rss = luaState->create_table(); + if (this->rss.bridge.has_value()) { + rss["bridge"] = this->rss.bridge.value(); } else { - url["rssbridge"] = sol::lua_nil; + rss["bridge"] = sol::lua_nil; } - o["url"] = url; + rss["timeout"] = this->rss.timeout; + + o["rss"] = rss; return o; } std::optional parse_configuration_from_file( - const std::string &file_path) { + const std::string& file_path) { std::ifstream ifs(file_path); if (!ifs.is_open()) { @@ -92,6 +97,7 @@ namespace bot { OwnerConfiguration owner_cfg; UrlConfiguration url_cfg; TokenConfiguration token_cfg; + RssConfiguration rss_cfg; std::string line; while (std::getline(ifs, line, '\n')) { @@ -102,7 +108,7 @@ namespace bot { std::getline(iss, key, '='); std::getline(iss, value); - for (char &c : key) { + for (char& c : key) { c = tolower(c); } @@ -154,8 +160,12 @@ namespace bot { url_cfg.paste_service = value; } else if (key == "url.randompost") { url_cfg.randompost = value; - } else if (key == "url.rssbridge") { - url_cfg.rssbridge = value; + } + + else if (key == "rss.timeout") { + rss_cfg.timeout = std::stoi(value); + } else if (key == "rss.bridge") { + rss_cfg.bridge = value; } else if (key == "token.github") { @@ -170,6 +180,7 @@ namespace bot { cfg.kick_credentials = kick_crd_cfg; cfg.database = db_cfg; cfg.tokens = token_cfg; + cfg.rss = rss_cfg; log::info("Configuration", "Successfully loaded the file from '" + file_path + "'"); diff --git a/bot/src/config.hpp b/bot/src/config.hpp index 139c4f3..1a09463 100644 --- a/bot/src/config.hpp +++ b/bot/src/config.hpp @@ -52,13 +52,17 @@ namespace bot { std::optional help = std::nullopt; std::optional paste_service = std::nullopt; std::optional randompost = std::nullopt; - std::optional rssbridge = std::nullopt; }; struct TokenConfiguration { std::optional github_token = std::nullopt; }; + struct RssConfiguration { + std::optional bridge = std::nullopt; + int timeout = 60; + }; + struct Configuration { TwitchCredentialsConfiguration twitch_credentials; KickCredentialsConfiguration kick_credentials; @@ -67,10 +71,11 @@ namespace bot { OwnerConfiguration owner; UrlConfiguration url; TokenConfiguration tokens; + RssConfiguration rss; sol::table as_lua_table(std::shared_ptr luaState) const; }; std::optional parse_configuration_from_file( - const std::string &file_path); + const std::string& file_path); } diff --git a/bot/src/rss.cpp b/bot/src/rss.cpp index 6c4b06d..cc802a1 100644 --- a/bot/src/rss.cpp +++ b/bot/src/rss.cpp @@ -57,7 +57,7 @@ namespace bot { } void RSSListener::run() { - if (!this->configuration.url.rssbridge.has_value()) { + if (!this->configuration.rss.bridge.has_value()) { log::error("RSSListener", "RSS Bridge is not set!"); return; } @@ -65,7 +65,8 @@ namespace bot { while (true) { this->add_channels(); this->check_channels(); - std::this_thread::sleep_for(std::chrono::seconds(60)); + std::this_thread::sleep_for( + std::chrono::seconds(this->configuration.rss.timeout)); } } @@ -142,7 +143,7 @@ namespace bot { std::string url = useRSSBridge - ? fmt::format(*this->configuration.url.rssbridge, bridge, name) + ? fmt::format(*this->configuration.rss.bridge, bridge, name) : name; std::optional channel = get_rss_channel(url); -- cgit v1.2.3