From 17d4d000e86da5a2a9e0ca11a5d1ad410bc1e8de Mon Sep 17 00:00:00 2001 From: Aras14HD Date: Thu, 26 Feb 2026 16:01:54 +0100 Subject: [PATCH 1/2] (partially) revert monitoring for impossible disconnect --- Cargo.lock | 6 +- factorion-bot-discord/Cargo.toml | 4 +- factorion-bot-reddit/Cargo.toml | 4 +- factorion-bot-reddit/src/main.rs | 8 ++- factorion-bot-reddit/src/reddit_api.rs | 89 +++++++++++++------------- factorion-lib/Cargo.toml | 2 +- 6 files changed, 57 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efd395a..1881ab1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -399,7 +399,7 @@ dependencies = [ [[package]] name = "factorion-bot-discord" -version = "2.2.3" +version = "2.2.4" dependencies = [ "anyhow", "dotenvy", @@ -414,7 +414,7 @@ dependencies = [ [[package]] name = "factorion-bot-reddit" -version = "5.3.3" +version = "5.3.4" dependencies = [ "anyhow", "base64 0.22.1", @@ -434,7 +434,7 @@ dependencies = [ [[package]] name = "factorion-lib" -version = "4.2.3" +version = "4.2.4" dependencies = [ "arbtest", "chrono", diff --git a/factorion-bot-discord/Cargo.toml b/factorion-bot-discord/Cargo.toml index deb59c5..6bbf6d9 100644 --- a/factorion-bot-discord/Cargo.toml +++ b/factorion-bot-discord/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factorion-bot-discord" -version = "2.2.3" +version = "2.2.4" edition = "2024" description = "factorion-bot (for factorials and related) on Discord" license = "MIT" @@ -10,7 +10,7 @@ keywords = ["factorial", "termial", "bot", "math", "discord"] categories = ["mathematics", "web-programming", "parser-implementations"] [dependencies] -factorion-lib = { path = "../factorion-lib", version = "4.2.3", features = ["serde", "influxdb"] } +factorion-lib = { path = "../factorion-lib", version = "4.2.4", features = ["serde", "influxdb"] } serenity = { version = "0.12", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] } tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "time"] } dotenvy = "^0.15.7" diff --git a/factorion-bot-reddit/Cargo.toml b/factorion-bot-reddit/Cargo.toml index b316526..95ce976 100644 --- a/factorion-bot-reddit/Cargo.toml +++ b/factorion-bot-reddit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factorion-bot-reddit" -version = "5.3.3" +version = "5.3.4" edition = "2024" description = "factorion-bot (for factorials and related) on Reddit" license = "MIT" @@ -10,7 +10,7 @@ keywords = ["factorial", "termial", "bot", "math"] categories = ["mathematics", "web-programming", "parser-implementations"] [dependencies] -factorion-lib = {path = "../factorion-lib", version = "4.2.3", features = ["serde", "influxdb"]} +factorion-lib = {path = "../factorion-lib", version = "4.2.4", features = ["serde", "influxdb"]} reqwest = { version = "0.12.28", features = ["json", "native-tls"], default-features = false } serde = { version = "1.0.219", default-features = false, features = ["derive"] } serde_json = "1.0.140" diff --git a/factorion-bot-reddit/src/main.rs b/factorion-bot-reddit/src/main.rs index daf878b..9c1470f 100644 --- a/factorion-bot-reddit/src/main.rs +++ b/factorion-bot-reddit/src/main.rs @@ -277,7 +277,11 @@ async fn main() -> Result<(), Box> { continue; } let Ok(mut dense_id) = u64::from_str_radix(&comment.meta.thread, 36) else { - warn!("Failed to make id dense {}", comment.meta.thread); + if comment.meta.thread == "" { + info!("Empty thread id on comment {}", comment.meta.id); + } else { + warn!("Failed to make id dense {}", comment.meta.thread); + } continue; }; dense_id |= 3 << 61; @@ -413,7 +417,7 @@ async fn main() -> Result<(), Box> { if let Some(t) = t { rate = t; } else { - warn!("Missing ratelimit"); + info!("Missing ratelimit"); } factorion_lib::influxdb::reddit::log_comment_reply( influx_client, diff --git a/factorion-bot-reddit/src/reddit_api.rs b/factorion-bot-reddit/src/reddit_api.rs index f968a49..5f7e830 100644 --- a/factorion-bot-reddit/src/reddit_api.rs +++ b/factorion-bot-reddit/src/reddit_api.rs @@ -77,9 +77,9 @@ impl std::fmt::Display for RateLimitErr { impl std::error::Error for RateLimitErr {} #[derive(Debug, Clone, Default)] pub struct LastIds { - pub comments: (String, String), - pub posts: (String, String), - pub mentions: (String, String), + pub comments: String, + pub posts: String, + pub mentions: String, } impl RedditClient { @@ -209,7 +209,7 @@ impl RedditClient { let (subs_response, posts_response, mentions_response) = join!( OptionFuture::from(SUBREDDIT_URL.clone().map(|subreddit_url| { let request = self.client.get(subreddit_url); - let request = add_query(request, &last_ids.comments.0); + let request = add_query(request, &last_ids.comments); request.bearer_auth(&self.token.access_token).send() })), OptionFuture::from( @@ -218,14 +218,14 @@ impl RedditClient { .flatten() .map(|subreddit_url| { let request = self.client.get(subreddit_url); - let request = add_query(request, &last_ids.posts.0); + let request = add_query(request, &last_ids.posts); request.bearer_auth(&self.token.access_token).send() }) ), OptionFuture::from(check_mentions.then_some(MENTION_URL.clone()).map( |subreddit_url| { let request = self.client.get(subreddit_url); - let request = add_query(request, &last_ids.mentions.0); + let request = add_query(request, &last_ids.mentions); request.bearer_auth(&self.token.access_token).send() } )), @@ -265,14 +265,11 @@ impl RedditClient { reset_timer = Self::update_reset_timer(reset_timer, t); - if !a.is_empty() - && last_ids.mentions.1 != "" - && !a.iter().any(|x| x.meta.id == last_ids.mentions.1) + if last_ids.mentions != "" + && a.len() + == *COMMENT_COUNT.get().expect("Comment count uninitialized") as usize { - warn!( - "Failed to keep up with mentions. last_id: {}", - last_ids.mentions.1 - ); + warn!("Got a full response, meaning capacity is reached!"); } if let Some(id) = id { @@ -296,14 +293,11 @@ impl RedditClient { reset_timer = Self::update_reset_timer(reset_timer, t); - if !a.is_empty() - && last_ids.comments.1 != "" - && !a.iter().any(|x| x.meta.id == last_ids.comments.1) + if last_ids.comments != "" + && a.len() + == *COMMENT_COUNT.get().expect("Comment count uninitialized") as usize { - warn!( - "Failed to keep up with comments. last_id: {}", - last_ids.comments.1 - ); + warn!("Got a full response, meaning capacity is reached!"); } if let Some(id) = id { @@ -327,14 +321,11 @@ impl RedditClient { reset_timer = Self::update_reset_timer(reset_timer, t); - if !posts.is_empty() - && last_ids.posts.1 != "" - && !posts.iter().any(|x| x.meta.id == last_ids.posts.1) + if last_ids.posts != "" + && posts.len() + == *COMMENT_COUNT.get().expect("Comment count uninitialized") as usize { - warn!( - "Failed to keep up with posts. last_id: {}", - last_ids.posts.1 - ); + warn!("Got a full response, meaning capacity is reached!"); } if let Some(id) = id { @@ -603,17 +594,28 @@ impl RedditClient { fn check_response_status(response: &Response) -> Result<(), ()> { if !response.status().is_success() { - if response.status().as_u16() == 500 { - error!( + match response.status().as_u16() { + 500 => error!( "Failed to get comments. Statuscode: {:?}. Internal server error.", response.status() - ); - } else { - error!( + ), + 502 => error!( + "Failed to get comments. Statuscode: {:?}. Bad Gateway.", + response.status() + ), + 503 => error!( + "Failed to get comments. Statuscode: {:?}. Service unavailable.", + response.status() + ), + 504 => error!( + "Failed to get comments. Statuscode: {:?}. Gateway Timeout.", + response.status() + ), + _ => error!( "Failed to get comments. Statuscode: {:?}. Response: {:?}", response.status(), response - ); + ), } return Err(()); } @@ -637,7 +639,7 @@ impl RedditClient { Vec>, Vec<(String, (String, Commands, String))>, Option<(f64, f64)>, - Option<(String, String)>, + Option, ), Box, > { @@ -775,12 +777,10 @@ impl RedditClient { comments.push(extracted_comment); } let id = if comments.is_empty() { - warn!("No comments. Requested comment (last_id or summon) is gone."); - Some((String::new(), String::new())) + info!("No comments. Requested comment (last_id or summon) is gone."); + Some(String::new()) } else { - comments - .get(1) - .map(|o| (o.meta.id.clone(), comments.get(0).unwrap().meta.id.clone())) + comments.get(1).map(|o| o.meta.id.clone()) }; Ok(( @@ -1092,9 +1092,9 @@ mod tests { let _ = COMMENT_COUNT.set(100); let mut already_replied = vec![]; let mut last_ids = LastIds { - comments: ("t1_m86nsre".to_owned(), "".to_owned()), - posts: ("t3_83us27sa".to_owned(), "".to_owned()), - mentions: ("".to_owned(), "".to_owned()), + comments: "t1_m86nsre".to_owned(), + posts: "t3_83us27sa".to_owned(), + mentions: "".to_owned(), }; let (status, comments) = join!( async { @@ -1327,10 +1327,7 @@ mod tests { ); println!("{comments:?}"); assert_eq!(t, Some((350.0, 10.0))); - assert_eq!( - id.unwrap(), - ("t3_m38msug".to_owned(), "t3_m38msum".to_owned()) - ); + assert_eq!(id.unwrap(), "t3_m38msug".to_owned()); } #[test] diff --git a/factorion-lib/Cargo.toml b/factorion-lib/Cargo.toml index 830b13d..0c4e76f 100644 --- a/factorion-lib/Cargo.toml +++ b/factorion-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "factorion-lib" -version = "4.2.3" +version = "4.2.4" edition = "2024" description = "A library used to create bots to recognize and calculate factorials and related concepts" license = "MIT" From 29d5a14e6bbdae7c55ac3cf4b457657304c0f30a Mon Sep 17 00:00:00 2001 From: tolik518 Date: Thu, 26 Feb 2026 22:13:36 +0100 Subject: [PATCH 2/2] changed "Polling..." to debug --- factorion-bot-reddit/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/factorion-bot-reddit/src/main.rs b/factorion-bot-reddit/src/main.rs index 9c1470f..eb16a0e 100644 --- a/factorion-bot-reddit/src/main.rs +++ b/factorion-bot-reddit/src/main.rs @@ -7,7 +7,7 @@ use factorion_lib::{ locale::Locale, rug::{Complete, Integer, integer::IntegerExt64}, }; -use log::{error, info, warn}; +use log::{debug, error, info, warn}; use reddit_api::RedditClient; use reddit_api::id::DenseId; use serde::{Deserialize, Serialize}; @@ -224,7 +224,7 @@ async fn main() -> Result<(), Box> { // Polling Reddit for new comments for i in (0..u8::MAX).cycle() { - info!("Polling Reddit for new comments..."); + debug!("Polling Reddit for new comments..."); let mut thread_calcs_changed = false; let start = SystemTime::now();