Instance URL as config var
This commit is contained in:
parent
7a360527f2
commit
8c7ec97637
4 changed files with 11 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -90,7 +90,7 @@ checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ascendance-of-a-bookworm-bot"
|
name = "ascendance-of-a-bookworm-bot"
|
||||||
version = "0.1.0"
|
version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"lemmy_api_common",
|
"lemmy_api_common",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ascendance-of-a-bookworm-bot"
|
name = "ascendance-of-a-bookworm-bot"
|
||||||
version = "0.1.0"
|
version = "1.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub(crate) struct RedditLogin {
|
||||||
|
|
||||||
// Config structs
|
// Config structs
|
||||||
pub_struct!(Config {
|
pub_struct!(Config {
|
||||||
|
instance: String,
|
||||||
reddit_config: RedditConfig,
|
reddit_config: RedditConfig,
|
||||||
feeds: Vec<FeedSetting>,
|
feeds: Vec<FeedSetting>,
|
||||||
});
|
});
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -52,7 +52,7 @@ impl Bot {
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = CLIENT
|
let res = CLIENT
|
||||||
.post("https://lemmy.neshweb.net/api/v3/user/login")
|
.post(self.config.instance.clone() + "/api/v3/user/login")
|
||||||
.json(&login_params)
|
.json(&login_params)
|
||||||
.send()
|
.send()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -70,14 +70,14 @@ impl Bot {
|
||||||
|
|
||||||
pub(crate) fn post(&mut self, post_data: CreatePost) {
|
pub(crate) fn post(&mut self, post_data: CreatePost) {
|
||||||
let res = CLIENT
|
let res = CLIENT
|
||||||
.post("https://lemmy.neshweb.net/api/v3/post")
|
.post(self.config.instance.clone() + "/api/v3/post")
|
||||||
.json(&post_data)
|
.json(&post_data)
|
||||||
.send()
|
.send()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_posts(auth: &Sensitive<String>) -> GetPostsResponse {
|
fn list_posts(auth: &Sensitive<String>, base: String) -> GetPostsResponse {
|
||||||
let params = GetPosts {
|
let params = GetPosts {
|
||||||
type_: Some(ListingType::Local),
|
type_: Some(ListingType::Local),
|
||||||
sort: Some(SortType::New),
|
sort: Some(SortType::New),
|
||||||
|
@ -86,7 +86,7 @@ fn list_posts(auth: &Sensitive<String>) -> GetPostsResponse {
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = CLIENT
|
let res = CLIENT
|
||||||
.get("https://lemmy.neshweb.net/api/v3/post/list")
|
.get(base + "/api/v3/post/list")
|
||||||
.query(¶ms)
|
.query(¶ms)
|
||||||
.send()
|
.send()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -105,14 +105,14 @@ impl CommunitiesVector {
|
||||||
CommunitiesVector{ids: vec![]}
|
CommunitiesVector{ids: vec![]}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(&mut self, auth: &Sensitive<String>) {
|
fn load(&mut self, auth: &Sensitive<String>, base: &String) {
|
||||||
let params = ListCommunities {
|
let params = ListCommunities {
|
||||||
auth: Some(auth.clone()),
|
auth: Some(auth.clone()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = CLIENT
|
let res = CLIENT
|
||||||
.get("https://lemmy.neshweb.net/api/v3/community/list")
|
.get(base.clone() + "/api/v3/community/list")
|
||||||
.query(¶ms)
|
.query(¶ms)
|
||||||
.send()
|
.send()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -150,7 +150,7 @@ fn main() {
|
||||||
let mut this = Bot::new();
|
let mut this = Bot::new();
|
||||||
println!("{}", this.secrets.lemmy.username);
|
println!("{}", this.secrets.lemmy.username);
|
||||||
this.login();
|
this.login();
|
||||||
this.community_ids.load(&this.auth);
|
this.community_ids.load(&this.auth, &this.config.instance);
|
||||||
|
|
||||||
// Create empty eTag list
|
// Create empty eTag list
|
||||||
println!("TODO: Etag list");
|
println!("TODO: Etag list");
|
||||||
|
@ -168,7 +168,7 @@ fn main() {
|
||||||
if start.time() - old > chrono::Duration::seconds(6) {
|
if start.time() - old > chrono::Duration::seconds(6) {
|
||||||
old = start.time();
|
old = start.time();
|
||||||
this.config = Config::load();
|
this.config = Config::load();
|
||||||
this.community_ids.load(&this.auth);
|
this.community_ids.load(&this.auth, &this.config.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the polling process
|
// Start the polling process
|
||||||
|
|
Loading…
Reference in a new issue