diff --git a/Cargo.lock b/Cargo.lock index ad28b31..5a6490a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 787256d..c93197e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/config/mod.rs b/src/config/mod.rs index 82fce95..c449ffe 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -59,6 +59,7 @@ pub(crate) struct RedditLogin { // Config structs pub_struct!(Config { + instance: String, reddit_config: RedditConfig, feeds: Vec, }); diff --git a/src/main.rs b/src/main.rs index 8c8114c..617c333 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) -> GetPostsResponse { +fn list_posts(auth: &Sensitive, base: String) -> GetPostsResponse { let params = GetPosts { type_: Some(ListingType::Local), sort: Some(SortType::New), @@ -86,7 +86,7 @@ fn list_posts(auth: &Sensitive) -> GetPostsResponse { }; let res = CLIENT - .get("https://lemmy.neshweb.net/api/v3/post/list") + .get(base + "/api/v3/post/list") .query(¶ms) .send() .unwrap() @@ -105,14 +105,14 @@ impl CommunitiesVector { CommunitiesVector{ids: vec![]} } - fn load(&mut self, auth: &Sensitive) { + fn load(&mut self, auth: &Sensitive, 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(¶ms) .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