diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index ea8e03c..144e8ee 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use tokio::sync::mpsc::UnboundedReceiver; use tokio::sync::{Mutex, RwLock}; +use tokio::time::{sleep, Duration}; use twitch_irc::login::StaticLoginCredentials; use twitch_irc::message::{PrivmsgMessage, ServerMessage}; @@ -23,6 +24,7 @@ use crate::core::identity::{ChangeResult, IdentityManager, Permissible}; use crate::core::botlog; use crate::core::chat::Chat; + #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub enum ChType { Channel(String), @@ -109,6 +111,19 @@ impl BotInstance { ratelimiters.insert(Channel(String::from(chnl)), n); } + + tokio::spawn(async { + loop { + let routine_mins = 60 * 60 * 24 ; // Every 1 Day + // let routine_mins = 1; // Every 1 Minute + Log::remove_old_logs(); + Log::info(&format!("Internal Purge Routine Triggered - running every {} mins",routine_mins)); + Log::flush(); + sleep(Duration::from_secs(60 * routine_mins)).await + } + }); + + BotInstance { prefix, bot_channel: Channel(login_name), @@ -130,6 +145,7 @@ impl BotInstance { let mut msglock = botlock.incoming_messages.write().await; while let Some(message) = msglock.recv().await { + match message { ServerMessage::Notice(msg) => { botlog::notice( diff --git a/src/main.rs b/src/main.rs index 6c829b9..40b5598 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,13 @@ pub type BotAR = Arc>; pub async fn main() { Log::set_file_ext(Extension::Log); Log::set_level(Level::Trace); + Log::set_retention_days(2); // Log::set_level(Level::Notice); + + + + let bot = BotInstance::init().await; { @@ -53,3 +58,6 @@ pub async fn main() { let pstr = botlog::fatal("ERROR : EXIT Game loop", Some("main()".to_string()), None); panic!("{}", pstr); } + + +