Instance URL as config var

This commit is contained in:
Neshura 2023-06-19 22:10:28 +02:00
parent 7a360527f2
commit 8c7ec97637
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
4 changed files with 11 additions and 10 deletions

2
Cargo.lock generated
View file

@ -90,7 +90,7 @@ checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]]
name = "ascendance-of-a-bookworm-bot"
version = "0.1.0"
version = "1.1.0"
dependencies = [
"chrono",
"lemmy_api_common",

View file

@ -1,6 +1,6 @@
[package]
name = "ascendance-of-a-bookworm-bot"
version = "0.1.0"
version = "1.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -59,6 +59,7 @@ pub(crate) struct RedditLogin {
// Config structs
pub_struct!(Config {
instance: String,
reddit_config: RedditConfig,
feeds: Vec<FeedSetting>,
});

View file

@ -52,7 +52,7 @@ impl Bot {
};
let res = CLIENT
.post("https://lemmy.neshweb.net/api/v3/user/login")
.post(self.config.instance.clone() + "/api/v3/user/login")
.json(&login_params)
.send()
.unwrap();
@ -70,14 +70,14 @@ impl Bot {
pub(crate) fn post(&mut self, post_data: CreatePost) {
let res = CLIENT
.post("https://lemmy.neshweb.net/api/v3/post")
.post(self.config.instance.clone() + "/api/v3/post")
.json(&post_data)
.send()
.unwrap();
}
}
fn list_posts(auth: &Sensitive<String>) -> GetPostsResponse {
fn list_posts(auth: &Sensitive<String>, base: String) -> GetPostsResponse {
let params = GetPosts {
type_: Some(ListingType::Local),
sort: Some(SortType::New),
@ -86,7 +86,7 @@ fn list_posts(auth: &Sensitive<String>) -> GetPostsResponse {
};
let res = CLIENT
.get("https://lemmy.neshweb.net/api/v3/post/list")
.get(base + "/api/v3/post/list")
.query(&params)
.send()
.unwrap()
@ -105,14 +105,14 @@ impl CommunitiesVector {
CommunitiesVector{ids: vec![]}
}
fn load(&mut self, auth: &Sensitive<String>) {
fn load(&mut self, auth: &Sensitive<String>, base: &String) {
let params = ListCommunities {
auth: Some(auth.clone()),
..Default::default()
};
let res = CLIENT
.get("https://lemmy.neshweb.net/api/v3/community/list")
.get(base.clone() + "/api/v3/community/list")
.query(&params)
.send()
.unwrap()
@ -150,7 +150,7 @@ fn main() {
let mut this = Bot::new();
println!("{}", this.secrets.lemmy.username);
this.login();
this.community_ids.load(&this.auth);
this.community_ids.load(&this.auth, &this.config.instance);
// Create empty eTag list
println!("TODO: Etag list");
@ -168,7 +168,7 @@ fn main() {
if start.time() - old > chrono::Duration::seconds(6) {
old = start.time();
this.config = Config::load();
this.community_ids.load(&this.auth);
this.community_ids.load(&this.auth, &this.config.instance);
}
// Start the polling process