Compare commits

...

3 commits
3.2.1 ... main

3 changed files with 28 additions and 10 deletions

2
Cargo.lock generated
View file

@ -52,7 +52,7 @@ dependencies = [
[[package]] [[package]]
name = "aob-lemmy-bot" name = "aob-lemmy-bot"
version = "3.2.1" version = "3.2.2"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",

View file

@ -1,7 +1,7 @@
[package] [package]
authors = ["Neshura"] authors = ["Neshura"]
name = "aob-lemmy-bot" name = "aob-lemmy-bot"
version = "3.2.1" version = "3.2.2"
edition = "2021" edition = "2021"
description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club" description = "Bot for automatically posting new chapters of 'Ascendance of a Bookworm' released by J-Novel Club"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"

View file

@ -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 { macro_rules! error {
($msg:tt) => { ($msg:tt) => {
match connected_to_journal() { match connected_to_journal() {
@ -397,24 +406,33 @@ impl Lemmy {
let response: String = match self.get_data_query("/api/v3/post/list", &get_params).await { let response: String = match self.get_data_query("/api/v3/post/list", &get_params).await {
Some(data) => data, 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 { let json_data: GetPostsResponse = match self.parse_json(&response).await {
Some(data) => data, Some(data) => data,
None => return None, None => {
error!("Unable to parse post data");
return None
},
}; };
if json_data.posts[0].post.name == post.name { for api_post in json_data.posts {
Some(json_data.posts[0].post.id) if api_post.post.name == post.name {
} else { return Some(api_post.post.id);
None }
} }
let msg = format!("Unable to find post {}", post.name);
info!(msg);
None
} }
async fn post_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Option<String> { async fn post_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Option<String> {
let res = HTTP_CLIENT let res = HTTP_CLIENT
.post(format!("{}{route}", &self.instance)) .post(format!("{}{route}", &self.instance))
.bearer_auth(&self.jwt_token.to_string()) .bearer_auth(self.jwt_token.to_string())
.json(&json) .json(&json)
.send() .send()
.await; .await;
@ -424,7 +442,7 @@ impl Lemmy {
async fn get_data_query<T: Serialize>(&self, route: &str, param: &T ) -> Option<String> { async fn get_data_query<T: Serialize>(&self, route: &str, param: &T ) -> Option<String> {
let res = HTTP_CLIENT let res = HTTP_CLIENT
.get(format!("{}{route}", &self.instance)) .get(format!("{}{route}", &self.instance))
.bearer_auth(&self.jwt_token.to_string()) .bearer_auth(self.jwt_token.to_string())
.query(&param) .query(&param)
.send() .send()
.await; .await;