From da4220e02737d282df8f0ec9f4425be488580cad Mon Sep 17 00:00:00 2001 From: Neshura <neshura@neshweb.net> Date: Tue, 22 Apr 2025 13:27:32 +0200 Subject: [PATCH 1/7] Iterate over all returned posts from API rather than only the first one since pins stay at the top --- src/lemmy.rs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/lemmy.rs b/src/lemmy.rs index 6afe1e5..2af495b 100644 --- a/src/lemmy.rs +++ b/src/lemmy.rs @@ -23,6 +23,15 @@ macro_rules! debug { }; } +macro_rules! info { + ($msg:tt) => { + match connected_to_journal() { + true => log::info!("[INFO] {}", $msg), + false => println!("[INFO] {}", $msg), + } + }; +} + macro_rules! error { ($msg:tt) => { match connected_to_journal() { @@ -397,24 +406,32 @@ impl Lemmy { let response: String = match self.get_data_query("/api/v3/post/list", &get_params).await { Some(data) => data, - None => return None, + None => { + error!("Unable to query post list"); + return None + }, }; let json_data: GetPostsResponse = match self.parse_json(&response).await { Some(data) => data, - None => return None, + None => { + error!("Unable to parse post data"); + return None + }, }; - if json_data.posts[0].post.name == post.name { - Some(json_data.posts[0].post.id) - } else { - None + for api_post in json_data.posts { + if api_post.post.name == post.name { + return Some(api_post.post.id); + } } + info!("Unable to find post {}", post.name); + None } async fn post_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Option<String> { let res = HTTP_CLIENT .post(format!("{}{route}", &self.instance)) - .bearer_auth(&self.jwt_token.to_string()) + .bearer_auth(self.jwt_token.to_string()) .json(&json) .send() .await; @@ -424,7 +441,7 @@ impl Lemmy { async fn get_data_query<T: Serialize>(&self, route: &str, param: &T ) -> Option<String> { let res = HTTP_CLIENT .get(format!("{}{route}", &self.instance)) - .bearer_auth(&self.jwt_token.to_string()) + .bearer_auth(self.jwt_token.to_string()) .query(¶m) .send() .await; From 3abfaf55c135a2b668e797f73eaf798766e4cc39 Mon Sep 17 00:00:00 2001 From: Neshura <neshura@neshweb.net> Date: Tue, 22 Apr 2025 13:33:12 +0200 Subject: [PATCH 2/7] Syntax Fix --- src/lemmy.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lemmy.rs b/src/lemmy.rs index 2af495b..ccfb2d2 100644 --- a/src/lemmy.rs +++ b/src/lemmy.rs @@ -424,7 +424,8 @@ impl Lemmy { return Some(api_post.post.id); } } - info!("Unable to find post {}", post.name); + let msg = format!("Unable to find post {}", post.name); + info!(msg); None } From 13954f26aa8887e40f154c3b2a2e63f48dae6f7b Mon Sep 17 00:00:00 2001 From: Neshura <neshura@neshweb.net> Date: Tue, 22 Apr 2025 13:33:23 +0200 Subject: [PATCH 3/7] Release 3.2.2 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07245d6..c26d591 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,7 +52,7 @@ dependencies = [ [[package]] name = "aob-lemmy-bot" -version = "3.2.1" +version = "3.2.2" dependencies = [ "async-trait", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 43f3599..382aa18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Neshura"] name = "aob-lemmy-bot" -version = "3.2.1" +version = "3.2.2" edition = "2021" description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club" license = "GPL-3.0-or-later" From 10111ff61295e634eb9158c87bf545e5c24942db Mon Sep 17 00:00:00 2001 From: Neshura <neshura@neshweb.net> Date: Sat, 14 Jun 2025 20:21:23 +0200 Subject: [PATCH 4/7] Change API Version from Lemmy v3 to Piefed Alpha --- src/lemmy.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lemmy.rs b/src/lemmy.rs index ccfb2d2..9dc45ec 100644 --- a/src/lemmy.rs +++ b/src/lemmy.rs @@ -227,7 +227,7 @@ impl Lemmy { }; let response = match HTTP_CLIENT - .post(read_config.instance.to_owned() + "/api/v3/user/login") + .post(read_config.instance.to_owned() + "/api/alpha/user/login") .json(&login_params) .send() .await @@ -268,12 +268,12 @@ impl Lemmy { } pub(crate) async fn logout(&self) { - let _ = self.post_data_json("/api/v3/user/logout", &"").await; + let _ = self.post_data_json("/api/alpha/user/logout", &"").await; } pub(crate) async fn post(&self, post: CreatePost) -> Option<PostId> { - let response: String = match self.post_data_json("/api/v3/post", &post).await { + let response: String = match self.post_data_json("/api/alpha/post", &post).await { Some(data) => data, None => return None, }; @@ -286,7 +286,7 @@ impl Lemmy { } async fn feature(&self, params: FeaturePost) -> Option<PostView> { - let response: String = match self.post_data_json("/api/v3/post/feature", ¶ms).await { + let response: String = match self.post_data_json("/api/alpha/post/feature", ¶ms).await { Some(data) => data, None => return None, }; @@ -323,7 +323,7 @@ impl Lemmy { ..Default::default() }; - let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await { + let response: String = match self.get_data_query("/api/alpha/post/list", &list_params).await { Some(data) => data, None => return None, }; @@ -346,7 +346,7 @@ impl Lemmy { ..Default::default() }; - let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await { + let response: String = match self.get_data_query("/api/alpha/post/list", &list_params).await { Some(data) => data, None => return None, }; @@ -369,7 +369,7 @@ impl Lemmy { ..Default::default() }; - let response: String = match self.get_data_query("/api/v3/community/list", &list_params).await { + let response: String = match self.get_data_query("/api/alpha/community/list", &list_params).await { Some(data) => data, None => return, }; @@ -404,7 +404,7 @@ impl Lemmy { page_cursor: None, }; - let response: String = match self.get_data_query("/api/v3/post/list", &get_params).await { + let response: String = match self.get_data_query("/api/alpha/post/list", &get_params).await { Some(data) => data, None => { error!("Unable to query post list"); From 204d4137791a10acaece0c44f5baef6d33f54969 Mon Sep 17 00:00:00 2001 From: Neshura <neshura@neshweb.net> Date: Sat, 14 Jun 2025 20:21:36 +0200 Subject: [PATCH 5/7] Release 3.3.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c26d591..1872127 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,7 +52,7 @@ dependencies = [ [[package]] name = "aob-lemmy-bot" -version = "3.2.2" +version = "3.3.0" dependencies = [ "async-trait", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 382aa18..c5a18da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Neshura"] name = "aob-lemmy-bot" -version = "3.2.2" +version = "3.3.0" edition = "2021" description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club" license = "GPL-3.0-or-later" From 42aff098bdcfa93722ff561da02610cadd4c9d27 Mon Sep 17 00:00:00 2001 From: Neshura <neshura@neshweb.net> Date: Sat, 14 Jun 2025 20:52:05 +0200 Subject: [PATCH 6/7] Login Delay --- src/bot.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bot.rs b/src/bot.rs index ba0e8b9..3e0bde8 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -81,7 +81,10 @@ impl Bot { loop { let mut lemmy = match Lemmy::new(&self.shared_config).await { Ok(data) => data, - Err(_) => continue, + Err(_) => { + sleep(Duration::seconds(10).to_std().unwrap()).await; + continue; + }, }; lemmy.get_communities().await; From f3bb504cfd359347f4d00ea5a243eff2d0715d90 Mon Sep 17 00:00:00 2001 From: Neshura <neshura@neshweb.net> Date: Sat, 14 Jun 2025 20:52:15 +0200 Subject: [PATCH 7/7] Release 3.3.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1872127..734bb74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,7 +52,7 @@ dependencies = [ [[package]] name = "aob-lemmy-bot" -version = "3.3.0" +version = "3.3.1" dependencies = [ "async-trait", "chrono", diff --git a/Cargo.toml b/Cargo.toml index c5a18da..e97bea1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Neshura"] name = "aob-lemmy-bot" -version = "3.3.0" +version = "3.3.1" edition = "2021" description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club" license = "GPL-3.0-or-later"