Linter changes
Some checks failed
Run Tests on Code / run-tests (push) Successful in 0s
Build and Release Binary File / build (push) Has been cancelled
Build and Release Binary File / upload-release (push) Has been cancelled
Build and Release Binary File / run-tests (push) Has been cancelled

This commit is contained in:
Neshura 2023-12-17 20:35:37 +01:00
parent 079e9f5e11
commit 40e142ccc7
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
6 changed files with 29 additions and 56 deletions

View file

@ -21,7 +21,7 @@ pub(crate) async fn run(data: Arc<RwLock<SharedData>>){
let mut last_reload: DateTime<Utc>; let mut last_reload: DateTime<Utc>;
let mut lemmy: Lemmy; let mut lemmy: Lemmy;
let mut login_error: bool; let mut login_error: bool;
let communities: HashMap<String, CommunityId>; let mut communities = HashMap::new();
{ {
let mut shared_data = data.write().await; let mut shared_data = data.write().await;
@ -38,14 +38,9 @@ pub(crate) async fn run(data: Arc<RwLock<SharedData>>){
Err(e) => panic!("{}", e), Err(e) => panic!("{}", e),
}; };
login_error = false; 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; sleep(Duration::milliseconds(100).to_std().unwrap()).await;
} }
@ -75,7 +70,7 @@ pub(crate) async fn run(data: Arc<RwLock<SharedData>>){
} }
if shared_data.start - last_reload > Duration::seconds(shared_data.config.config_reload_seconds as i64) { 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, Ok(data) => data,
Err(e) => { Err(e) => {
login_error = true; login_error = true;
@ -106,7 +101,7 @@ pub(crate) async fn run(data: Arc<RwLock<SharedData>>){
}; };
} }
let down = shared_data.downgrade(); let _ = shared_data.downgrade();
idle(&data).await; idle(&data).await;
} }
@ -172,7 +167,7 @@ async fn handle_series<'a>(
let post_data = CustomCreatePost { let post_data = CustomCreatePost {
name: post_lemmy_info.title, name: post_lemmy_info.title,
community_id: community_id, community_id,
url: Some(post_lemmy_info.url), url: Some(post_lemmy_info.url),
body: post_body, body: post_body,
honeypot: None, honeypot: None,
@ -184,7 +179,7 @@ async fn handle_series<'a>(
if post_series_config.pin_settings.pin_new_post_community { if post_series_config.pin_settings.pin_new_post_community {
let pinned_posts = lemmy.get_community_pinned(community_id).await?; 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]; let community_pinned_post = &pinned_posts[0];
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Community).await?; 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 { if post_series_config.pin_settings.pin_new_post_local {
let pinned_posts = lemmy.get_local_pinned().await?; 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]; let community_pinned_post = &pinned_posts[0];
lemmy.unpin(community_pinned_post.post.id, PostFeatureType::Local).await?; 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); 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.set_series(series.slug.as_str(), series_history);
data.post_history.save_history(); let _ = data.post_history.save_history();
} }
Ok(()) Ok(())
} }

View file

@ -11,10 +11,6 @@ pub(crate) struct Config {
} }
impl Config { impl Config {
pub(crate) fn new() -> Result<Self, Box<dyn Error>> {
todo!()
}
pub(crate) fn load() -> Result<Self, Box<dyn Error>> { pub(crate) fn load() -> Result<Self, Box<dyn Error>> {
let cfg: Self = confy::load_path("./config.toml")?; let cfg: Self = confy::load_path("./config.toml")?;
if cfg.instance.is_empty() { if cfg.instance.is_empty() {
@ -28,10 +24,6 @@ impl Config {
}); });
Ok(cfg) Ok(cfg)
} }
pub(crate) fn save() -> Result<(), Box<dyn Error>> {
todo!()
}
} }
impl Default for Config { impl Default for Config {

View file

@ -84,17 +84,6 @@ pub(crate) enum PartInfo {
} }
impl 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 { pub(crate) fn as_u8(&self) -> u8 {
match self { match self {
Part(number) => *number, Part(number) => *number,
@ -147,7 +136,7 @@ impl PartialOrd for PartInfo {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) enum PostInfo { 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 }, Volume { part: PartInfo, description: String, lemmy_info: LemmyPostInfo },
} }
@ -161,15 +150,15 @@ impl PostInfo {
pub(crate) fn get_lemmy_info(&self) -> LemmyPostInfo { pub(crate) fn get_lemmy_info(&self) -> LemmyPostInfo {
match self { match self {
Chapter {lemmy_info: lemmy_info, ..} => lemmy_info.clone(), Chapter {lemmy_info, ..} => lemmy_info.clone(),
Volume {lemmy_info: lemmy_info, ..} => lemmy_info.clone() Volume {lemmy_info, ..} => lemmy_info.clone()
} }
} }
pub(crate) fn get_description(&self) -> Option<String> { pub(crate) fn get_description(&self) -> Option<String> {
match self { match self {
_Chapter => None, Chapter {..} => None,
Volume {description, ..} => Some(description.clone()) 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? { if let Some(prepub_info) = get_latest_prepub(&volume.slug).await? {
let prepub_post_info = Chapter { let prepub_post_info = Chapter {
part: new_part_info, part: new_part_info,
volume: volume.number,
lemmy_info: prepub_info lemmy_info: prepub_info
}; };

View file

@ -20,11 +20,11 @@ pub(crate) struct Credentials {
impl Credentials { impl Credentials {
pub(crate) fn get_username(&self) -> Sensitive<String> { pub(crate) fn get_username(&self) -> Sensitive<String> {
return Sensitive::new(self.username.clone()); Sensitive::new(self.username.clone())
} }
pub(crate) fn get_password(&self) -> Sensitive<String> { pub(crate) fn get_password(&self) -> Sensitive<String> {
return Sensitive::new(self.password.clone()); Sensitive::new(self.password.clone())
} }
pub(crate) fn set_credentials() -> Result<Self, VarError> { pub(crate) fn set_credentials() -> Result<Self, VarError> {
@ -63,10 +63,10 @@ pub(crate) async fn login(credentials: &Credentials, instance: &str) -> Result<L
jwt_token: token.clone(), jwt_token: token.clone(),
instance: instance.to_string(), instance: instance.to_string(),
}), }),
None => 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); communities.insert(community.name, community.id);
} }
return Ok(communities) Ok(communities)
} }
} }

View file

@ -1,14 +1,13 @@
use chrono::{DateTime, Duration, Timelike, Utc}; use chrono::{DateTime, Duration, Utc};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use reqwest::{Client}; use reqwest::{Client};
use std::str::FromStr; use std::{collections::HashMap, vec};
use std::{collections::HashMap, error::Error, vec};
use std::fmt::Debug; use std::fmt::Debug;
use std::sync::{Arc}; use std::sync::{Arc};
use tokio::sync::{RwLock}; use tokio::sync::{RwLock};
use std::thread::sleep;
use dotenv::dotenv; use dotenv::dotenv;
use strum_macros::Display; use strum_macros::Display;
use tokio::time::sleep;
use crate::config::Config; use crate::config::Config;
use crate::post_history::{SeriesHistory}; use crate::post_history::{SeriesHistory};
@ -20,12 +19,11 @@ mod tui;
mod post_history; mod post_history;
pub static HTTP_CLIENT: Lazy<Client> = Lazy::new(|| { pub static HTTP_CLIENT: Lazy<Client> = Lazy::new(|| {
let client = Client::builder() Client::builder()
.timeout(Duration::seconds(30).to_std().unwrap()) .timeout(Duration::seconds(30).to_std().unwrap())
.connect_timeout(Duration::seconds(30).to_std().unwrap()) .connect_timeout(Duration::seconds(30).to_std().unwrap())
.build() .build()
.expect("build client"); .expect("build client")
client
}); });
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -56,9 +54,9 @@ impl SharedData {
pub(crate) fn get_messages(&self, errors: bool, warnings: bool, infos: bool) -> Vec<Message> { pub(crate) fn get_messages(&self, errors: bool, warnings: bool, infos: bool) -> Vec<Message> {
self.messages.iter().filter(|msg| { self.messages.iter().filter(|msg| {
match msg { match msg {
Message::Error(_) => true && errors, Message::Error(_) => errors,
Message::Warning(_) => true && warnings, Message::Warning(_) => warnings,
Message::Info(_) => true && infos, Message::Info(_) => infos,
} }
}).cloned().collect() }).cloned().collect()
} }
@ -89,7 +87,7 @@ async fn main() {
tui_thread.abort(); tui_thread.abort();
data = persistent_data.read().await.clone(); data = persistent_data.read().await.clone();
data.messages.push(Message::Error(format!("Bot crashed due to unknown Error, restarting thread after wait..."))); 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")); sleep(Duration::seconds(5).to_std().expect("Conversion should always work since static")).await;
} }
} }

View file

@ -56,7 +56,7 @@ impl SeriesHistory {
return part_info.volume == title || part_info.chapter == title return part_info.volume == title || part_info.chapter == title
} }
} }
return false false
} }
pub(crate) fn get_series(&self, series: &str) -> PostHistory { pub(crate) fn get_series(&self, series: &str) -> PostHistory {