botlog module

This commit is contained in:
ModulatingForce 2024-03-02 10:06:26 -05:00
parent a2747b1ad5
commit 90b9b66e6d
9 changed files with 404 additions and 238 deletions

View file

@ -1,4 +1,5 @@
pub mod botinstance;
pub mod botlog;
pub mod botmodules;
pub mod identity;
pub mod ratelimiter;

View file

@ -1,15 +1,14 @@
use std::sync::Arc;
use std::env;
use std::collections::HashMap;
use std::env;
use std::sync::Arc;
use tokio::sync::mpsc::UnboundedReceiver;
use tokio::sync::{RwLock,Mutex};
use tokio::sync::{Mutex, RwLock};
use twitch_irc::login::StaticLoginCredentials;
use twitch_irc::message::{PrivmsgMessage,ServerMessage};
use twitch_irc::transport::tcp::{TCPTransport,TLS};
use twitch_irc::{ClientConfig,SecureTCPTransport,TwitchIRCClient};
use twitch_irc::message::{PrivmsgMessage, ServerMessage};
use twitch_irc::transport::tcp::{TCPTransport, TLS};
use twitch_irc::{ClientConfig, SecureTCPTransport, TwitchIRCClient};
use dotenv::dotenv;
@ -20,189 +19,188 @@ use rand::Rng;
use crate::core::ratelimiter;
use crate::core::ratelimiter::RateLimiter;
use crate::core::botmodules::ModulesManager;
use crate::core::botmodules::bot_actions::actions_util::BotAR;
use crate::core::botmodules::ModulesManager;
use crate::core::identity::{ChangeResult, IdentityManager, Permissible};
use crate::core::botlog;
pub mod botlog {
// pub mod botlog {
/*
Module intends to add some layers to logging with the module user only requiring to pass :
- String Log message
- Option<String> - Code_Module
- Option<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
*/
// /*
// Module intends to add some layers to logging with the module user only requiring to pass :
// - String Log message
// - Option<String> - Code_Module
// - Option<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
// */
// // use casual_logger::{Level, Log};
// use casual_logger::Log;
// use twitch_irc::message::PrivmsgMessage;
// use casual_logger::{Level, Log};
use casual_logger::Log;
use twitch_irc::message::PrivmsgMessage;
// // trace, debug, info, notice, warn, error, fatal
// trace, debug, info, notice, warn, error, fatal
// /*
/*
// in main : Log::debug("Checking bot actions", Some("main()".to_string()), None);
in main : Log::debug("Checking bot actions", Some("main()".to_string()), None);
// in log :
// [blalba@timestmp]
// debug = "Checking bot actions",
in log :
[blalba@timestmp]
debug = "Checking bot actions",
// */
// pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
// let (chnl, chatter) = match in_prvmsg {
// Some(prvmsg) => {
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
// (
// Some(prvmsg.channel_login.clone()),
// Some(prvmsg.sender.name.clone()),
// ) // <-- Clone fine atm while we're just working with Strings
// }
// None => (None, None),
// };
*/
// Log::trace_t(
// in_msg,
// casual_logger::Table::default() //
// .str("Channel", &format!("{:?}", chnl))
// .str("Chatter", &format!("{:?}", chatter))
// .str("Code_Module", &format!("{:?}", in_module)),
// );
// }
pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
// pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
// let (chnl, chatter) = match in_prvmsg {
// Some(prvmsg) => {
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
// (
// Some(prvmsg.channel_login.clone()),
// Some(prvmsg.sender.name.clone()),
// ) // <-- Clone fine atm while we're just working with Strings
// }
// None => (None, None),
// };
Log::trace_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
// Log::debug_t(
// in_msg,
// casual_logger::Table::default() //
// .str("Channel", &format!("{:?}", chnl))
// .str("Chatter", &format!("{:?}", chatter))
// .str("Code_Module", &format!("{:?}", in_module)),
// );
// }
pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
// pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
// let (chnl, chatter) = match in_prvmsg {
// Some(prvmsg) => {
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
// (
// Some(prvmsg.channel_login.clone()),
// Some(prvmsg.sender.name.clone()),
// ) // <-- Clone fine atm while we're just working with Strings
// }
// None => (None, None),
// };
Log::debug_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
// Log::info_t(
// in_msg,
// casual_logger::Table::default() //
// .str("Channel", &format!("{:?}", chnl))
// .str("Chatter", &format!("{:?}", chatter))
// .str("Code_Module", &format!("{:?}", in_module)),
// );
// }
pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
// pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
// let (chnl, chatter) = match in_prvmsg {
// Some(prvmsg) => {
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
// (
// Some(prvmsg.channel_login.clone()),
// Some(prvmsg.sender.name.clone()),
// ) // <-- Clone fine atm while we're just working with Strings
// }
// None => (None, None),
// };
Log::info_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
// Log::notice_t(
// in_msg,
// casual_logger::Table::default() //
// .str("Channel", &format!("{:?}", chnl))
// .str("Chatter", &format!("{:?}", chatter))
// .str("Code_Module", &format!("{:?}", in_module)),
// );
// }
pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
// pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
// let (chnl, chatter) = match in_prvmsg {
// Some(prvmsg) => {
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
// (
// Some(prvmsg.channel_login.clone()),
// Some(prvmsg.sender.name.clone()),
// ) // <-- Clone fine atm while we're just working with Strings
// }
// None => (None, None),
// };
Log::notice_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
// Log::warn_t(
// in_msg,
// casual_logger::Table::default() //
// .str("Channel", &format!("{:?}", chnl))
// .str("Chatter", &format!("{:?}", chatter))
// .str("Code_Module", &format!("{:?}", in_module)),
// );
// }
pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
// pub fn error(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
// let (chnl, chatter) = match in_prvmsg {
// Some(prvmsg) => {
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
// (
// Some(prvmsg.channel_login.clone()),
// Some(prvmsg.sender.name.clone()),
// ) // <-- Clone fine atm while we're just working with Strings
// }
// None => (None, None),
// };
Log::warn_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
// Log::error_t(
// in_msg,
// casual_logger::Table::default() //
// .str("Channel", &format!("{:?}", chnl))
// .str("Chatter", &format!("{:?}", chatter))
// .str("Code_Module", &format!("{:?}", in_module)),
// );
// }
pub fn error(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
// pub fn fatal<'a>(
// in_msg: &'a str,
// in_module: Option<String>,
// in_prvmsg: Option<&PrivmsgMessage>,
// ) -> &'a str {
// let (chnl, chatter) = match in_prvmsg {
// Some(prvmsg) => {
// //Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
// (
// Some(prvmsg.channel_login.clone()),
// Some(prvmsg.sender.name.clone()),
// ) // <-- Clone fine atm while we're just working with Strings
// }
// None => (None, None),
// };
Log::error_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
// Log::fatal_t(
// in_msg,
// casual_logger::Table::default() //
// .str("Channel", &format!("{:?}", chnl))
// .str("Chatter", &format!("{:?}", chatter))
// .str("Code_Module", &format!("{:?}", in_module)),
// );
pub fn fatal<'a>(
in_msg: &'a str,
in_module: Option<String>,
in_prvmsg: Option<&PrivmsgMessage>,
) -> &'a str {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
Log::fatal_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
in_msg
}
}
// in_msg
// }
// }
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum ChType {

175
src/core/botlog.rs Normal file
View file

@ -0,0 +1,175 @@
/*
Module intends to add some layers to logging with the module user only requiring to pass :
- String Log message
- Option<String> - Code_Module
- Option<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
*/
// use casual_logger::{Level, Log};
use casual_logger::Log;
use twitch_irc::message::PrivmsgMessage;
// trace, debug, info, notice, warn, error, fatal
/*
in main : Log::debug("Checking bot actions", Some("main()".to_string()), None);
in log :
[blalba@timestmp]
debug = "Checking bot actions",
*/
pub fn trace(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
Log::trace_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
pub fn debug(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
Log::debug_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
Log::info_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
pub fn notice(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
Log::notice_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
Log::warn_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
pub fn error(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
Log::error_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
}
pub fn fatal<'a>(
in_msg: &'a str,
in_module: Option<String>,
in_prvmsg: Option<&PrivmsgMessage>,
) -> &'a str {
let (chnl, chatter) = match in_prvmsg {
Some(prvmsg) => {
//Log::trace(&format!("(#{}) {}: {}", prvmsg.channel_login, prvmsg.sender.name, prvmsg.message_text));
(
Some(prvmsg.channel_login.clone()),
Some(prvmsg.sender.name.clone()),
) // <-- Clone fine atm while we're just working with Strings
}
None => (None, None),
};
Log::fatal_t(
in_msg,
casual_logger::Table::default() //
.str("Channel", &format!("{:?}", chnl))
.str("Chatter", &format!("{:?}", chatter))
.str("Code_Module", &format!("{:?}", in_module)),
);
in_msg
}

View file

@ -15,7 +15,9 @@ use tokio::sync::RwLock;
// Important to use tokios Mutex here since std Mutex doesn't work with async functions
// use tokio::sync::Mutex;
use crate::core::botinstance::{self, botlog, BotInstance};
use crate::core::botinstance::{self, BotInstance};
use crate::core::botlog;
// use std::rc::Rc;
// use tokio::sync::RwLock;
@ -185,7 +187,7 @@ impl BotActionTrait for Listener {
async fn add_to_bot(self, bot: BotInstance) {
// println!("Adding action to bot");
// Log::trace("Adding action to bot");
botinstance::botlog::trace(
botlog::trace(
"Adding action to bot",
Some("BotModules > BotActionTrait > add_to_bot()".to_string()),
None,
@ -197,7 +199,7 @@ impl BotActionTrait for Listener {
// let modmgr = *modmgr.lock().await;
// println!("Adding action to module manager");
// Log::trace("Adding action to module manager");
botinstance::botlog::trace(
botlog::trace(
"Adding action to module manager",
Some("BotModules > BotActionTrait > add_to_bot()".to_string()),
None,

View file

@ -7,7 +7,8 @@ use crate::core::botmodules::bot_actions::actions_util;
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
// use crate::core::botinstance::{self, botlog, BotInstance, ChType};
use crate::core::botinstance::{self, ChType};
use crate::core::botinstance::ChType;
use crate::core::botlog;
// use futures::lock::Mutex;
// use twitch_irc::message::{Badge, PrivmsgMessage};
use twitch_irc::message::PrivmsgMessage;
@ -34,7 +35,7 @@ fn adminvector() -> Vec<String> {
// pub fn init(mgr:&mut ModulesManager)
pub async fn init(mgr: Arc<ModulesManager>) {
// println!("Went into Identiy Module init");
botinstance::botlog::trace(
botlog::trace(
"Went into Identiy Module init",
Some("identity.rs > init()".to_string()),
None,
@ -61,7 +62,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) {
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// println!("Called cmd promote");
botinstance::botlog::trace(
botlog::trace(
"Called cmd promote",
Some("identity.rs > cmd_prommote()".to_string()),
Some(&msg),
@ -94,7 +95,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/
// println!("{}",msg.message_text);
botinstance::botlog::trace(
botlog::trace(
&format!("Twich Message > {}", msg.message_text),
Some("identity.rs > cmd_promote()".to_string()),
None,
@ -144,7 +145,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let rslt = match targetusr {
Some(targetusr) => {
botinstance::botlog::debug(
botlog::debug(
// &format!("running promote()"),
"running promote()",
Some("identity.rs > cmd_promote()".to_string()),
@ -170,7 +171,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
}
None => {
botinstance::botlog::debug(
botlog::debug(
// &format!("No Targer User argument"),
"No Targer User argument",
Some("identity.rs > cmd_demote()".to_string()),
@ -188,7 +189,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Success(a) => {
// println!("Succesfully promoted : {a} ;");
let outmsg = &format!("o7 Successfully promoted : {a}");
botinstance::botlog::debug(
botlog::debug(
outmsg,
Some("identity.rs > cmd_prommote()".to_string()),
Some(&msg),
@ -203,7 +204,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Failed(a) => {
// println!("Failed to promote : {a} ; ");
let outmsg = &format!("PoroSad failed to promote : {a}");
botinstance::botlog::debug(
botlog::debug(
outmsg,
Some("identity.rs > cmd_prommote()".to_string()),
Some(&msg),
@ -218,7 +219,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::NoChange(a) => {
// println!("No Changes Made : {a} ; ");
let outmsg = &format!("uuh No Promotion Change : {a}");
botinstance::botlog::debug(
botlog::debug(
outmsg,
Some("identity.rs > cmd_prommote()".to_string()),
Some(&msg),
@ -486,7 +487,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/
botinstance::botlog::trace(
botlog::trace(
// &format!("End of cmd_promote()"),
"End of cmd_promote()",
Some("identity.rs > cmd_prommote()".to_string()),
@ -527,7 +528,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// async fn cmd_demote(mut _chat:Arc<Mutex<BotInstance>>,_msg:PrivmsgMessage) {
async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) {
// println!("Called cmd demote");
botinstance::botlog::debug(
botlog::debug(
"Called cmd demote",
Some("identity.rs > cmd_demote()".to_string()),
Some(&msg),
@ -669,7 +670,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let rslt = match targetusr {
Some(targetusr) => {
botinstance::botlog::debug(
botlog::debug(
// &format!("running demote()"),
"running demote()",
Some("identity.rs > cmd_demote()".to_string()),
@ -688,7 +689,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
}
None => {
botinstance::botlog::debug(
botlog::debug(
// &format!("No Targer User argument"),
"No Targer User argument",
Some("identity.rs > cmd_demote()".to_string()),
@ -746,7 +747,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Success(a) => {
// println!("Succesfully promoted : {a} ;");
let outmsg = &format!("o7 Successfully demoted : {a}");
botinstance::botlog::debug(
botlog::debug(
outmsg,
Some("identity.rs > cmd_demote()".to_string()),
Some(&msg),
@ -761,7 +762,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::Failed(a) => {
// println!("Failed to promote : {a} ; ");
let outmsg = &format!("PoroSad failed to demote : {a}");
botinstance::botlog::debug(
botlog::debug(
outmsg,
Some("identity.rs > cmd_demote()".to_string()),
Some(&msg),
@ -776,7 +777,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
ChangeResult::NoChange(a) => {
// println!("No Changes Made : {a} ; ");
let outmsg = &format!("uuh No Demotion Change : {a}");
botinstance::botlog::debug(
botlog::debug(
outmsg,
Some("identity.rs > cmd_demote()".to_string()),
Some(&msg),
@ -813,7 +814,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// async fn getroles(bot:Arc<Mutex<BotInstance>>,msg:PrivmsgMessage) {
async fn getroles(bot: BotAR, msg: PrivmsgMessage) {
// println!("Called cmd getroles");
botinstance::botlog::debug(
botlog::debug(
"Called cmd getroles",
Some("identity.rs > cmd_getroles()".to_string()),
Some(&msg),
@ -888,21 +889,21 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// let a = bot.get_identity();
let botlock = bot.read().await;
// println!("botlock read");
botinstance::botlog::trace(
botlog::trace(
"botlock read",
Some("identity.rs > init > getroles()".to_string()),
Some(&msg),
);
let idlock = botlock.get_identity();
// println!("got identity");
botinstance::botlog::trace(
botlog::trace(
"got identity",
Some("identity.rs > init > getroles()".to_string()),
Some(&msg),
);
let idlock = idlock.read().await; // <-- 02.12 - Latest where it gest stuck - before or at this point
// println!("id lock");
botinstance::botlog::trace(
botlog::trace(
"id lock",
Some("identity.rs > init > getroles()".to_string()),
Some(&msg),
@ -1003,7 +1004,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// let sproles = idlock.getspecialuserroles(String::from(targetuser),).await;
// println!("Retrieved User Roles >> {:?}",sproles);
botinstance::botlog::debug(
botlog::debug(
&format!("User roles of Target Chatter >> {:?}", sproles),
Some("identity.rs > init > getroles()".to_string()),
Some(&msg),
@ -1011,7 +1012,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// # I believe at this stage I still have botlock active
botinstance::botlog::debug(
botlog::debug(
// &format!("Evaluating special roles"),
"Evaluating special roles",
Some("identity.rs > init > getroles()".to_string()),
@ -1091,7 +1092,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// let a = bot.identity.getuserroles(String::from("ModulatingForce"), Some(ChType::Channel(String::from("ModulatingForcebot"))));
// println!("{:?}",a);
botinstance::botlog::debug(
botlog::debug(
&format!("Chat Say Reply message : {:?}", outmsg),
Some("identity.rs > init > getroles()".to_string()),
Some(&msg),
@ -1102,7 +1103,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
}
// println!("End of Init MOdule add");
botinstance::botlog::trace(
botlog::trace(
"End of Init MOdule add",
Some("identity.rs > init ".to_string()),
None,
@ -1215,7 +1216,7 @@ impl IdentityManager {
srulock
.entry(trgchatter.clone())
.or_insert(Arc::new(RwLock::new(vec![])));
botinstance::botlog::trace(
botlog::trace(
&format!(
"Ensuring User in Roles {:?}",
srulock.entry(trgchatter.clone())
@ -1240,7 +1241,7 @@ impl IdentityManager {
// [ ] Check what Badges in PrivmsgMessage
// println!{"Checking within PRVMSG"};
botinstance::botlog::debug(
botlog::debug(
"Checking within PRVMSG",
Some("identity.rs > can_user_run_PRVMSG()".to_string()),
// Some(&msg),
@ -1327,7 +1328,7 @@ impl IdentityManager {
cmdreqroles: Vec<UserRole>, // ) -> Result<Permissible,Box<dyn Error>> {
) -> (Permissible, ChangeResult) {
// println!{"Checking within can_user_run()"};
botinstance::botlog::debug(
botlog::debug(
&format!(
"Checking within can_user_run() :
usr : {} ; channel : {:?} ; badge : {:?} ; cmdreqroles : {:?}",
@ -1410,7 +1411,7 @@ impl IdentityManager {
// [x] If not, assign them UserRole::Mod(channelname::ChType)
Some(ChatBadge::Mod) => {
// println!("Mod Chatbadge detected");
botinstance::botlog::info(
botlog::info(
"Mod Chatbadge detected",
Some("identity.rs > can_user_run()".to_string()),
None,
@ -1423,7 +1424,7 @@ impl IdentityManager {
// match self.special_roles_users.get_mut(&usr.to_lowercase()) {
// match self.special_roles_users.get(&usr.to_lowercase()) {
// println!("Creating clone");
botinstance::botlog::trace(
botlog::trace(
"Creating arc clone",
Some("identity.rs > can_user_run()".to_string()),
None,
@ -1433,7 +1434,7 @@ impl IdentityManager {
let roleslock = Arc::clone(&self.special_roles_users);
// println!("Read lock on : Special_Roles_User"); // <-- after this is slightly different between working and problem
botinstance::botlog::trace(
botlog::trace(
"Read lock on : Special_Roles_User",
Some("identity.rs > can_user_run()".to_string()),
None,
@ -1468,7 +1469,7 @@ impl IdentityManager {
// Do nothing when theh have a mod badge and have either a supmod or mod badge for the channel
// println!("Already a mod in roles");
botinstance::botlog::trace(
botlog::trace(
"Already a mod in roles",
Some("identity.rs > can_user_run()".to_string()),
None,
@ -1477,13 +1478,13 @@ impl IdentityManager {
_ => {
// In the event they have a mod badge , are running a bot command, but don't have a channel mod role yet...
// println!("lock created > adding with a mod role o7");
botinstance::botlog::trace(
botlog::trace(
"lock created > adding with a mod role o7",
Some("identity.rs > can_user_run()".to_string()),
None,
);
// botinstance::botlog::notice("Assigning ModRole to Chatter",
// botlog::notice("Assigning ModRole to Chatter",
// Some("identity.rs > can_user_run()".to_string()), None);
let mut roleslock = roleslock;
@ -1510,7 +1511,7 @@ impl IdentityManager {
// [x] If cmdreqroles includes UserRole::Mod("") , checks if chatter has UserRole::Mod(channelname::ChType) or UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow)
// println!("cmd required roles : {:?}",cmdreqroles);
botinstance::botlog::trace(
botlog::trace(
&format!("cmd required roles : {:?}", cmdreqroles),
Some("identity.rs > can_user_run()".to_string()),
None,
@ -1524,7 +1525,7 @@ impl IdentityManager {
// }
// println!("Command requires Mod Role");
botinstance::botlog::trace(
botlog::trace(
"Command requires Mod Role",
Some("identity.rs > can_user_run()".to_string()),
None,
@ -1542,7 +1543,7 @@ impl IdentityManager {
.get(&usr.to_lowercase())
{
// println!("Special roles found for user");
botinstance::botlog::trace(
botlog::trace(
"Special roles found for user",
Some("identity.rs > can_user_run()".to_string()),
None,
@ -1555,7 +1556,7 @@ impl IdentityManager {
{
// return Ok(Permissible::Allow);
// println!("Special roles found for user : A mod idenfified ");
botinstance::botlog::trace(
botlog::trace(
"> Special Role Identified : Mod ",
Some("identity.rs > can_user_run()".to_string()),
None,
@ -1592,7 +1593,7 @@ impl IdentityManager {
// [x] If cmdreqroles includes UserRole::BotAdmin and chatter has UserRole::BotAdmin , Ok(Permissible::Allow)
// println!("Eval cmdreqroles with botadmin : {}",cmdreqroles.contains(&UserRole::BotAdmin));
botinstance::botlog::trace(
botlog::trace(
&format!(
"Eval cmdreqroles with botadmin : {}",
cmdreqroles.contains(&UserRole::BotAdmin)
@ -1603,7 +1604,7 @@ impl IdentityManager {
if cmdreqroles.contains(&UserRole::BotAdmin) {
// println!("special roles get : {:?}",(&*self).special_roles_users.read().await.get(&usr.to_lowercase()));
botinstance::botlog::trace(
botlog::trace(
&format!(
"special roles get : {:?}",
// (&*self)
@ -1631,7 +1632,7 @@ impl IdentityManager {
"special roles contains BotAdmin: {}",
a.read().await.contains(&UserRole::BotAdmin)
);
botinstance::botlog::trace(
botlog::trace(
&format!(
"special roles contains BotAdmin: {}",
a.read().await.contains(&UserRole::BotAdmin)
@ -1662,7 +1663,7 @@ impl IdentityManager {
channel: Option<ChType>,
trg_role: Option<UserRole>,
) -> ChangeResult {
botinstance::botlog::trace(
botlog::trace(
&format!(
"IN VARS for promote() : auth : {} ; authbadge : {:?} ; trg : {} ; Channel {:?} ; {:?}",
authorizer,authorizer_badge,trgchatter,channel,trg_role),
@ -1929,7 +1930,7 @@ impl IdentityManager {
// Some("identity.rs > promote()".to_string()),
// None,
// );
botinstance::botlog::warn(
botlog::warn(
"Code Warning : add handing for other trgusrroles",
Some("identity.rs > promote()".to_string()),
None,
@ -2265,7 +2266,7 @@ impl IdentityManager {
// Some("identity.rs > promote()".to_string()),
// None,
// );
botinstance::botlog::warn(
botlog::warn(
"Runtime reached undeveloped code",
Some("identity.rs > promote()".to_string()),
None,
@ -2283,7 +2284,7 @@ impl IdentityManager {
) -> ChangeResult {
// botinstance::botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?} ; Targer Role {:?}",
// authorizer,trgchatter,channel,trg_role),
botinstance::botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?}",
botlog::trace(&format!("IN VARS for demote() : Authorizer : {:?} ; Target Chatter : {} ; Target Channel : {:?}",
authorizer,trgchatter,channel), Some("identity.rs > demote()".to_string()), None);
Log::flush();
@ -2403,7 +2404,7 @@ impl IdentityManager {
// botinstance::botlog::warn(&format!("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling"),
// Some("identity.rs > demote()".to_string()), None);
botinstance::botlog::warn("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling",
botlog::warn("Potential Unhandled Demotion Condition : Consider explicitely adding in for better handling",
Some("identity.rs > demote()".to_string()), None);
Log::flush();
ChangeResult::Failed(String::from("Did not meet criteria to demote succesfully"))
@ -2420,7 +2421,7 @@ impl IdentityManager {
*/
// [ ] !!! TODO: I don't think below is evaluating by given channel
botinstance::botlog::debug(
botlog::debug(
&format!(
"IN VARS > chattername {} ; channel {:?}",
chattername, channel
@ -2467,14 +2468,14 @@ impl IdentityManager {
Some(channel) => {
// let eval = a.read().await.contains(&UserRole::Mod(channel));
// let eval = a.read().await.contains(&UserRole::SupMod(channel));
botinstance::botlog::debug(
botlog::debug(
&format!("INTERNAL > All Roles found {:?}", &a),
Some("IdentityManager > getspecialuserroles()".to_string()),
None,
);
// a.read().await.contains(&UserRole::BotAdmin)
botinstance::botlog::trace(
botlog::trace(
&format!(
"INTERNAL > eval special roles contains botadmin : {:?}",
a.read().await.contains(&UserRole::BotAdmin)
@ -2514,7 +2515,7 @@ impl IdentityManager {
}
}
botinstance::botlog::debug(
botlog::debug(
&format!("OUT > evalsproles {:?}", &evalsproles),
Some("IdentityManager > getspecialuserroles()".to_string()),
None,

View file

@ -12,7 +12,7 @@ pub struct RateLimiter {
pub enum LimiterResp {
Allow, // when it's evaluated to be within limits
Skip, // as outside of rate limits
// Enqueue, // [FUTURE]
// Enqueue, // [FUTURE]
}
impl Default for RateLimiter {

View file

@ -3,7 +3,8 @@ use tokio::sync::RwLock;
use casual_logger::{Extension, Level, Log};
use bot_lib::core::botinstance::{BotInstance,botlog};
use bot_lib::core::botinstance::BotInstance;
use bot_lib::core::botlog;
use bot_lib::core::botmodules;
pub type BotAR = Arc<RwLock<BotInstance>>;
@ -48,7 +49,6 @@ pub async fn main() {
bot.runner().await;
let pstr =
botlog::fatal("ERROR : EXIT Game loop", Some("main()".to_string()), None);
let pstr = botlog::fatal("ERROR : EXIT Game loop", Some("main()".to_string()), None);
panic!("{}", pstr);
}

View file

@ -20,5 +20,4 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// this is achieved by calling submodules that also have fn init() defined
experiments::init(mgr).await
}

View file

@ -1,22 +1,21 @@
/*
Custom Modules -
Usage :
Usage :
[ ] within the file's init(), define BotActions & Load them into the ModulesManager
[ ] Define Execution Bodies for these BotActions
[ ] Define Execution Bodies for these BotActions
[ ] Afterwards, add the following to parent modules.rs file
- mod <modulename>;
- within init(), <modulename>::init(mgr).await
*/
use std::sync::Arc;
use rand::Rng;
use std::sync::Arc;
use twitch_irc::message::PrivmsgMessage;
use crate::core::botinstance::botlog;
use crate::core::botlog;
use crate::core::botmodules::bot_actions::actions_util::{self, BotAR};
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
@ -24,8 +23,6 @@ use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, M
use crate::core::identity;
pub async fn init(mgr: Arc<ModulesManager>) {
// 1. Define the BotAction
let botc1 = BotCommand {
module: BotModule(String::from("experiments001")),
@ -39,7 +36,6 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// 2. Add the BotAction to ModulesManager
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
// 1. Define the BotAction
let list1 = Listener {
module: BotModule(String::from("experiments001")),
@ -50,11 +46,9 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// 2. Add the BotAction to ModulesManager
list1.add_to_modmgr(Arc::clone(&mgr)).await;
}
async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
// [ ] Uses gen_ratio() to output bool based on a ratio probability .
// - For example gen_ratio(2,3) is 2 out of 3 or 0.67% (numerator,denomitator)
// - More Info : https://rust-random.github.io/rand/rand/trait.Rng.html#method.gen_ratio
@ -62,18 +56,15 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
if msg.sender.name.to_lowercase() == "ModulatingForce".to_lowercase()
|| msg.sender.name.to_lowercase() == "mzNToRi".to_lowercase()
{
botlog::debug(
"Good Girl Detected > Pausechamp",
Some("experiments > goodgirl()".to_string()),
Some(&msg),
);
let rollwin = rand::thread_rng().gen_ratio(1, 8);
if rollwin {
botlog::debug(
"Oh that's a good girl!",
Some("experiments > goodgirl()".to_string()),
@ -90,7 +81,6 @@ async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
.chat
.say_in_reply_to(&msg, String::from("GoodGirl xdd "))
.await;
}
}
}