summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-12-01 16:50:39 +0500
committerilotterytea <iltsu@alright.party>2025-12-01 16:50:39 +0500
commit0d36a1ee88fb7aedf5b33af7ac95140b002c5a64 (patch)
tree7f51f629da03376e214c7683f738b05ed4be3816
parent71a4a8d6fc4a84029939003107bfbaad33b8c6ce (diff)
feat: rss timeout
-rw-r--r--bot/src/config.cpp27
-rw-r--r--bot/src/config.hpp9
-rw-r--r--bot/src/rss.cpp7
-rw-r--r--luamods/telegram.lua4
-rw-r--r--luamods/twitter.lua4
5 files changed, 34 insertions, 17 deletions
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<Configuration> 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<std::string> help = std::nullopt;
std::optional<std::string> paste_service = std::nullopt;
std::optional<std::string> randompost = std::nullopt;
- std::optional<std::string> rssbridge = std::nullopt;
};
struct TokenConfiguration {
std::optional<std::string> github_token = std::nullopt;
};
+ struct RssConfiguration {
+ std::optional<std::string> 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<sol::state> luaState) const;
};
std::optional<Configuration> 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<RSSChannel> channel = get_rss_channel(url);
diff --git a/luamods/telegram.lua b/luamods/telegram.lua
index 760b0a5..220e414 100644
--- a/luamods/telegram.lua
+++ b/luamods/telegram.lua
@@ -37,7 +37,7 @@ Get the latest post from the specified public Telegram channel.
minimal_rights = "user",
handle = function(request)
local cfg = bot_config()
- if cfg.url.rssbridge == nil then
+ if cfg.rss.bridge == nil then
return l10n_custom_formatted_line_request(request, lines, "not_configured", {})
end
@@ -45,7 +45,7 @@ Get the latest post from the specified public Telegram channel.
return l10n_custom_formatted_line_request(request, lines, "no_value", {})
end
- local url = str_format(cfg.url.rssbridge, { "TelegramBridge", request.message })
+ local url = str_format(cfg.rss.bridge, { "TelegramBridge", request.message })
local channel = rss_get(url)
if channel == nil then
return l10n_custom_formatted_line_request(request, lines, "not_found", { request.message })
diff --git a/luamods/twitter.lua b/luamods/twitter.lua
index da71500..aaacd5f 100644
--- a/luamods/twitter.lua
+++ b/luamods/twitter.lua
@@ -38,7 +38,7 @@ Get the latest post from the specified Twitter account.
minimal_rights = "user",
handle = function(request)
local cfg = bot_config()
- if cfg.url.rssbridge == nil then
+ if cfg.rss.bridge == nil then
return l10n_custom_formatted_line_request(request, lines, "not_configured", {})
end
@@ -46,7 +46,7 @@ Get the latest post from the specified Twitter account.
return l10n_custom_formatted_line_request(request, lines, "no_value", {})
end
- local url = str_format(cfg.url.rssbridge, { "FarsideNitterBridge", request.message })
+ local url = str_format(cfg.rss.bridge, { "FarsideNitterBridge", request.message })
local channel = rss_get(url)
if channel == nil then
return l10n_custom_formatted_line_request(request, lines, "not_found", { request.message })