Compare commits

..

No commits in common. "main" and "3.2.1" have entirely different histories.
main ... 3.2.1

4 changed files with 19 additions and 40 deletions

2
Cargo.lock generated
View file

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

View file

@ -1,7 +1,7 @@
[package]
authors = ["Neshura"]
name = "aob-lemmy-bot"
version = "3.3.1"
version = "3.2.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"

View file

@ -81,10 +81,7 @@ impl Bot {
loop {
let mut lemmy = match Lemmy::new(&self.shared_config).await {
Ok(data) => data,
Err(_) => {
sleep(Duration::seconds(10).to_std().unwrap()).await;
continue;
},
Err(_) => continue,
};
lemmy.get_communities().await;

View file

@ -23,15 +23,6 @@ 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() {
@ -227,7 +218,7 @@ impl Lemmy {
};
let response = match HTTP_CLIENT
.post(read_config.instance.to_owned() + "/api/alpha/user/login")
.post(read_config.instance.to_owned() + "/api/v3/user/login")
.json(&login_params)
.send()
.await
@ -268,12 +259,12 @@ impl Lemmy {
}
pub(crate) async fn logout(&self) {
let _ = self.post_data_json("/api/alpha/user/logout", &"").await;
let _ = self.post_data_json("/api/v3/user/logout", &"").await;
}
pub(crate) async fn post(&self, post: CreatePost) -> Option<PostId> {
let response: String = match self.post_data_json("/api/alpha/post", &post).await {
let response: String = match self.post_data_json("/api/v3/post", &post).await {
Some(data) => data,
None => return None,
};
@ -286,7 +277,7 @@ impl Lemmy {
}
async fn feature(&self, params: FeaturePost) -> Option<PostView> {
let response: String = match self.post_data_json("/api/alpha/post/feature", &params).await {
let response: String = match self.post_data_json("/api/v3/post/feature", &params).await {
Some(data) => data,
None => return None,
};
@ -323,7 +314,7 @@ impl Lemmy {
..Default::default()
};
let response: String = match self.get_data_query("/api/alpha/post/list", &list_params).await {
let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await {
Some(data) => data,
None => return None,
};
@ -346,7 +337,7 @@ impl Lemmy {
..Default::default()
};
let response: String = match self.get_data_query("/api/alpha/post/list", &list_params).await {
let response: String = match self.get_data_query("/api/v3/post/list", &list_params).await {
Some(data) => data,
None => return None,
};
@ -369,7 +360,7 @@ impl Lemmy {
..Default::default()
};
let response: String = match self.get_data_query("/api/alpha/community/list", &list_params).await {
let response: String = match self.get_data_query("/api/v3/community/list", &list_params).await {
Some(data) => data,
None => return,
};
@ -404,35 +395,26 @@ impl Lemmy {
page_cursor: None,
};
let response: String = match self.get_data_query("/api/alpha/post/list", &get_params).await {
let response: String = match self.get_data_query("/api/v3/post/list", &get_params).await {
Some(data) => data,
None => {
error!("Unable to query post list");
return None
},
None => return None,
};
let json_data: GetPostsResponse = match self.parse_json(&response).await {
Some(data) => data,
None => {
error!("Unable to parse post data");
return None
},
None => return None,
};
for api_post in json_data.posts {
if api_post.post.name == post.name {
return Some(api_post.post.id);
}
if json_data.posts[0].post.name == post.name {
Some(json_data.posts[0].post.id)
} else {
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> {
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;
@ -442,7 +424,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(&param)
.send()
.await;