Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions factorion-bot-discord/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions factorion-bot-reddit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions factorion-bot-reddit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -224,7 +224,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// 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();
Expand Down Expand Up @@ -277,7 +277,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
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;
Expand Down Expand Up @@ -413,7 +417,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
if let Some(t) = t {
rate = t;
} else {
warn!("Missing ratelimit");
info!("Missing ratelimit");
}
factorion_lib::influxdb::reddit::log_comment_reply(
influx_client,
Expand Down
89 changes: 43 additions & 46 deletions factorion-bot-reddit/src/reddit_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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()
}
)),
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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(());
}
Expand All @@ -637,7 +639,7 @@ impl RedditClient {
Vec<CommentConstructed<Meta>>,
Vec<(String, (String, Commands, String))>,
Option<(f64, f64)>,
Option<(String, String)>,
Option<String>,
),
Box<dyn std::error::Error>,
> {
Expand Down Expand Up @@ -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((
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion factorion-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down