diff --git a/src/bot/mod.rs b/src/bot/mod.rs index be34858..1090c7c 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -21,7 +21,7 @@ pub(crate) async fn run(data: Arc>){ let mut last_reload: DateTime; let mut lemmy: Lemmy; let mut login_error: bool; - let communities: HashMap; + let mut communities = HashMap::new(); { let mut shared_data = data.write().await; @@ -38,14 +38,9 @@ pub(crate) async fn run(data: Arc>){ Err(e) => panic!("{}", e), }; login_error = false; - - communities = match lemmy.get_communities().await { - Ok(data) => data, - Err(e) => panic!("{}", e), - }; } - while (Utc::now().naive_local().second() != 30) { + while Utc::now().naive_local().second() != 30 { sleep(Duration::milliseconds(100).to_std().unwrap()).await; } @@ -75,7 +70,7 @@ pub(crate) async fn run(data: Arc>){ } if shared_data.start - last_reload > Duration::seconds(shared_data.config.config_reload_seconds as i64) { - let communities = match lemmy.get_communities().await { + communities = match lemmy.get_communities().await { Ok(data) => data, Err(e) => { login_error = true; @@ -106,7 +101,7 @@ pub(crate) async fn run(data: Arc>){ }; } - let down = shared_data.downgrade(); + let _ = shared_data.downgrade(); idle(&data).await; } @@ -172,7 +167,7 @@ async fn handle_series<'a>( let post_data = CustomCreatePost { name: post_lemmy_info.title, - community_id: community_id, + community_id, url: Some(post_lemmy_info.url), body: post_body, honeypot: None, @@ -184,7 +179,7 @@ async fn handle_series<'a>( if post_series_config.pin_settings.pin_new_post_community { let pinned_posts = lemmy.get_community_pinned(community_id).await?; - if pinned_posts.len() > 0 { + if !pinned_posts.is_empty() { let community_pinned_post = &pinned_posts[0]; lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Community).await?; } @@ -193,7 +188,7 @@ async fn handle_series<'a>( if post_series_config.pin_settings.pin_new_post_local { let pinned_posts = lemmy.get_local_pinned().await?; - if pinned_posts.len() > 0 { + if !pinned_posts.is_empty() { let community_pinned_post = &pinned_posts[0]; lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Local).await?; } @@ -214,7 +209,7 @@ async fn handle_series<'a>( series_history.set_part(post_part_info.as_string().as_str(), part_history); data.post_history.set_series(series.slug.as_str(), series_history); - data.post_history.save_history(); + let _ = data.post_history.save_history(); } Ok(()) } diff --git a/src/config/mod.rs b/src/config/mod.rs index 0a9604e..e0fc5eb 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -11,10 +11,6 @@ pub(crate) struct Config { } impl Config { - pub(crate) fn new() -> Result> { - todo!() - } - pub(crate) fn load() -> Result> { let cfg: Self = confy::load_path("./config.toml")?; if cfg.instance.is_empty() { @@ -28,10 +24,6 @@ impl Config { }); Ok(cfg) } - - pub(crate) fn save() -> Result<(), Box> { - todo!() - } } impl Default for Config { diff --git a/src/jnovel/mod.rs b/src/jnovel/mod.rs index c5dff33..e872023 100644 --- a/src/jnovel/mod.rs +++ b/src/jnovel/mod.rs @@ -84,17 +84,6 @@ pub(crate) enum PartInfo { } impl PartInfo { - pub(crate) fn is_parts(&self) -> bool { - match self { - Part(_) => true, - NoParts => false, - } - } - - pub(crate) fn is_no_parts(&self) -> bool { - !self.is_parts() - } - pub(crate) fn as_u8(&self) -> u8 { match self { Part(number) => *number, @@ -147,7 +136,7 @@ impl PartialOrd for PartInfo { #[derive(Debug, Clone)] pub(crate) enum PostInfo { - Chapter { part: PartInfo, volume: u8, lemmy_info: LemmyPostInfo }, + Chapter { part: PartInfo, lemmy_info: LemmyPostInfo }, Volume { part: PartInfo, description: String, lemmy_info: LemmyPostInfo }, } @@ -161,15 +150,15 @@ impl PostInfo { pub(crate) fn get_lemmy_info(&self) -> LemmyPostInfo { match self { - Chapter {lemmy_info: lemmy_info, ..} => lemmy_info.clone(), - Volume {lemmy_info: lemmy_info, ..} => lemmy_info.clone() + Chapter {lemmy_info, ..} => lemmy_info.clone(), + Volume {lemmy_info, ..} => lemmy_info.clone() } } pub(crate) fn get_description(&self) -> Option { match self { - _Chapter => None, - Volume {description, ..} => Some(description.clone()) + Chapter {..} => None, + Volume {description, ..} => Some(description.clone()), } } } @@ -312,7 +301,6 @@ pub(crate) async fn check_feed(series_slug: &str, series_has_parts: bool) -> Res if let Some(prepub_info) = get_latest_prepub(&volume.slug).await? { let prepub_post_info = Chapter { part: new_part_info, - volume: volume.number, lemmy_info: prepub_info }; diff --git a/src/lemmy/mod.rs b/src/lemmy/mod.rs index c3dffe3..ce39711 100644 --- a/src/lemmy/mod.rs +++ b/src/lemmy/mod.rs @@ -20,11 +20,11 @@ pub(crate) struct Credentials { impl Credentials { pub(crate) fn get_username(&self) -> Sensitive { - return Sensitive::new(self.username.clone()); + Sensitive::new(self.username.clone()) } pub(crate) fn get_password(&self) -> Sensitive { - return Sensitive::new(self.password.clone()); + Sensitive::new(self.password.clone()) } pub(crate) fn set_credentials() -> Result { @@ -63,10 +63,10 @@ pub(crate) async fn login(credentials: &Credentials, instance: &str) -> Result Err(panic!("Login did not return JWT token. Are the credentials valid?")) + None => panic!("Login did not return JWT token. Are the credentials valid?") } }, - status => Err(panic!("Unexpected HTTP Status '{}' during Login", status.to_string())) + status => panic!("Unexpected HTTP Status '{}' during Login", status) } } @@ -196,7 +196,7 @@ impl Lemmy { communities.insert(community.name, community.id); } - return Ok(communities) + Ok(communities) } } diff --git a/src/main.rs b/src/main.rs index c23f98f..76e5ddf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,13 @@ -use chrono::{DateTime, Duration, Timelike, Utc}; +use chrono::{DateTime, Duration, Utc}; use once_cell::sync::Lazy; use reqwest::{Client}; -use std::str::FromStr; -use std::{collections::HashMap, error::Error, vec}; +use std::{collections::HashMap, vec}; use std::fmt::Debug; use std::sync::{Arc}; use tokio::sync::{RwLock}; -use std::thread::sleep; use dotenv::dotenv; use strum_macros::Display; +use tokio::time::sleep; use crate::config::Config; use crate::post_history::{SeriesHistory}; @@ -20,12 +19,11 @@ mod tui; mod post_history; pub static HTTP_CLIENT: Lazy = Lazy::new(|| { - let client = Client::builder() + Client::builder() .timeout(Duration::seconds(30).to_std().unwrap()) .connect_timeout(Duration::seconds(30).to_std().unwrap()) .build() - .expect("build client"); - client + .expect("build client") }); #[derive(Clone, Debug)] @@ -56,9 +54,9 @@ impl SharedData { pub(crate) fn get_messages(&self, errors: bool, warnings: bool, infos: bool) -> Vec { self.messages.iter().filter(|msg| { match msg { - Message::Error(_) => true && errors, - Message::Warning(_) => true && warnings, - Message::Info(_) => true && infos, + Message::Error(_) => errors, + Message::Warning(_) => warnings, + Message::Info(_) => infos, } }).cloned().collect() } @@ -89,7 +87,7 @@ async fn main() { tui_thread.abort(); data = persistent_data.read().await.clone(); - data.messages.push(Message::Error(format!("Bot crashed due to unknown Error, restarting thread after wait..."))); - sleep(Duration::seconds(5).to_std().expect("Conversion should always work since static")); + data.messages.push(Message::Error("Bot crashed due to unknown Error, restarting thread after wait...".to_string())); + sleep(Duration::seconds(5).to_std().expect("Conversion should always work since static")).await; } } diff --git a/src/post_history/mod.rs b/src/post_history/mod.rs index 7d685e1..fe27e52 100644 --- a/src/post_history/mod.rs +++ b/src/post_history/mod.rs @@ -56,7 +56,7 @@ impl SeriesHistory { return part_info.volume == title || part_info.chapter == title } } - return false + false } pub(crate) fn get_series(&self, series: &str) -> PostHistory {