From b9a26a7b1cf3833c9332e161af7d164e2f6bdc10 Mon Sep 17 00:00:00 2001 From: Neshura Date: Mon, 8 Jan 2024 21:07:17 +0100 Subject: [PATCH] Partially adapt bot module to changes due to fetchers modularization --- src/bot.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index fa08bea..eef7e6a 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -1,8 +1,8 @@ use crate::config::{Config, PostBody, SeriesConfig}; -use crate::jnovel::PostInfo; -use crate::lemmy::Lemmy; +use crate::fetchers::jnovel::JPostInfo; +use crate::lemmy::{Lemmy, PostInfo}; use crate::post_history::SeriesHistory; -use crate::{jnovel, lemmy, write_error, write_info, write_warn, SharedData}; +use crate::{fetchers::{jnovel}, lemmy, write_error, write_info, write_warn, SharedData}; use chrono::{DateTime, Duration, Utc}; use lemmy_api_common::post::CreatePost; use lemmy_db_schema::newtypes::{CommunityId, LanguageId}; @@ -11,6 +11,7 @@ use std::collections::HashMap; use std::sync::Arc; use tokio::sync::RwLock; use tokio::time::sleep; +use crate::fetchers::Fetcher; pub(crate) async fn run(data: Arc>) { let mut last_reload: DateTime; @@ -137,15 +138,16 @@ async fn idle(data: &Arc>) { } async fn handle_series(series: &SeriesConfig, communities: &HashMap, lemmy: &Lemmy, data: &Arc>) -> Result<(), ()> { - let mut post_list = match jnovel::check_feed(series.slug.as_str(), series.parted).await { + let jnc = jnovel::JFetcherOptions::new(series.slug.clone(), series.parted); + let post_list = match jnc.check_feed().await { Ok(data) => data, Err(_) => return Err(()), }; - for (index, post_info) in post_list.clone().iter().enumerate() { + for post_info in post_list.clone().iter() { // todo .clone() likely not needed let post_part_info = post_info.get_part_info(); - let post_lemmy_info = post_info.get_lemmy_info(); + let post_lemmy_info = post_info.get_info(); { let read = data.read().await; @@ -159,8 +161,8 @@ async fn handle_series(series: &SeriesConfig, communities: &HashMap &series.prepub_community, - PostInfo::Volume { .. } => &series.volume_community, + JPostInfo::Chapter { .. } => &series.prepub_community, + JPostInfo::Volume { .. } => &series.volume_community, }; let community_id = *communities @@ -256,8 +258,8 @@ async fn handle_series(series: &SeriesConfig, communities: &HashMap part_history.chapter = post_info.get_lemmy_info().title, - PostInfo::Volume { .. } => part_history.volume = post_info.get_lemmy_info().title, + JPostInfo::Chapter { .. } => part_history.chapter = post_info.get_info().title, + JPostInfo::Volume { .. } => part_history.volume = post_info.get_info().title, } series_history.set_part(post_part_info.as_string().as_str(), part_history);