fmt & clippy

This commit is contained in:
ModulatingForce 2024-03-01 23:36:37 -05:00
parent e032cfb918
commit d998e2f290
8 changed files with 228 additions and 161 deletions

View file

@ -16,5 +16,5 @@ casual_logger = "0.6.5"
[lib]
name = "botLib"
name = "bot_lib"
path = "src/lib.rs"

View file

@ -11,9 +11,9 @@ use twitch_irc::SecureTCPTransport;
use twitch_irc::TwitchIRCClient;
// use std::borrow::Borrow;
use dotenv::dotenv;
use std::borrow::BorrowMut;
use std::boxed;
use std::cell::Ref;
// use std::borrow::BorrowMut;
// use std::boxed;
// use std::cell::Ref;
use std::env;
use std::collections::HashMap;
@ -23,30 +23,29 @@ use rand::Rng;
// Important to use tokios Mutex here since std Mutex doesn't work with async functions
use tokio::sync::Mutex;
use crate::core::botmodules::BotAction;
// use crate::core::botmodules::BotAction;
use crate::core::ratelimiter;
use crate::core::ratelimiter::RateLimiter;
use crate::core::botmodules;
// use crate::core::botmodules;
use crate::core::botmodules::ModulesManager;
use crate::core::identity::{ChangeResult, IdentityManager, Permissible};
use std::cell::RefCell;
use std::rc::Rc;
// use std::cell::RefCell;
// use std::rc::Rc;
use std::sync::Arc;
// use futures::lock::Mutex;
use std::pin::Pin;
// use std::pin::Pin;
//use std::borrow::Borrow;
use core::borrow::Borrow;
// use core::borrow::Borrow;
// pub type BotAR = Arc<RwLock<BotInstance>>;
use super::botmodules::bot_actions::actions_util::BotAR;
use casual_logger::{Level, Log};
// use casual_logger::{Level, Log};
use casual_logger::Log;
pub mod botlog {
@ -57,7 +56,8 @@ pub mod botlog {
- Option<PrivmsgMessage> - this is used to parse out Chatter & Channel into the logs
*/
use casual_logger::{Level, Log};
// use casual_logger::{Level, Log};
use casual_logger::Log;
use twitch_irc::message::PrivmsgMessage;
// trace, debug, info, notice, warn, error, fatal
@ -72,11 +72,7 @@ pub mod botlog {
*/
pub fn trace(
in_msg: &str,
in_module: Option<String>,
in_prvmsg: Option<&PrivmsgMessage>,
) -> () {
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));
@ -97,11 +93,7 @@ pub mod botlog {
);
}
pub fn debug(
in_msg: &str,
in_module: Option<String>,
in_prvmsg: Option<&PrivmsgMessage>,
) -> () {
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));
@ -122,7 +114,7 @@ pub mod botlog {
);
}
pub fn info(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) -> () {
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));
@ -143,11 +135,7 @@ pub mod botlog {
);
}
pub fn notice(
in_msg: &str,
in_module: Option<String>,
in_prvmsg: Option<&PrivmsgMessage>,
) -> () {
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));
@ -168,7 +156,7 @@ pub mod botlog {
);
}
pub fn warn(in_msg: &str, in_module: Option<String>, in_prvmsg: Option<&PrivmsgMessage>) -> () {
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));
@ -189,11 +177,7 @@ pub mod botlog {
);
}
pub fn error(
in_msg: &str,
in_module: Option<String>,
in_prvmsg: Option<&PrivmsgMessage>,
) -> () {
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));
@ -262,17 +246,18 @@ impl Chat {
) -> Chat {
Chat {
ratelimiters: Arc::new(Mutex::new(ratelimiters)),
client: client,
// client: client,
client,
}
}
pub async fn init_channel(&mut self, chnl: ChType) -> () {
pub async fn init_channel(&mut self, chnl: ChType) {
let n = RateLimiter::new();
self.ratelimiters.lock().await.insert(chnl, n);
}
// pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () {
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, mut outmsg: String) -> () {
pub async fn say_in_reply_to(&self, msg: &PrivmsgMessage, mut outmsg: String) {
/*
formats message before sending to TwitchIRC
@ -308,7 +293,7 @@ impl Chat {
msg.channel_login, "rate limit counter increase"
),
Some("Chat > say_in_reply_to".to_string()),
Some(&msg),
Some(msg),
);
contextratelimiter.increment_counter();
// println!("{:?}",self.ratelimiters);
@ -316,29 +301,29 @@ impl Chat {
botlog::trace(
&format!("{:?}", self.ratelimiters),
Some("Chat > say_in_reply_to".to_string()),
Some(&msg),
Some(msg),
);
}
ratelimiter::LimiterResp::Skip => {
(); // do nothing otherwise
// (); // do nothing otherwise
}
}
Log::flush();
}
async fn say(&self, _: String, _: String) -> () {
async fn _say(&self, _: String, _: String) {
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
// self.client.say(msg,outmsg).await.unwrap();
}
async fn me(&self, _: String, _: String) -> () {
async fn _me(&self, _: String, _: String) {
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
// self.client.me(msg,outmsg).await.unwrap();
}
async fn me_in_reply_to(&self, _: String, _: String) -> () {
async fn _me_in_reply_to(&self, _: String, _: String) {
// more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say
// self.client.me(msg,outmsg).await.unwrap();
@ -363,7 +348,7 @@ impl BotManagers {
}
}
pub fn rIdentity(self) -> Arc<RwLock<IdentityManager>> {
pub fn r_identity(self) -> Arc<RwLock<IdentityManager>> {
self.identity
}
}
@ -446,7 +431,8 @@ impl BotInstance {
// };
BotInstance {
prefix: prefix,
// prefix: prefix,
prefix,
bot_channel: Channel(login_name),
incoming_messages: Arc::new(RwLock::new(incoming_messages)),
botmodules: ModulesManager::init().await,
@ -458,7 +444,7 @@ impl BotInstance {
// b
}
pub async fn runner(self) -> () {
pub async fn runner(self) {
let bot = Arc::new(RwLock::new(self));
let join_handle = tokio::spawn(async move {
@ -503,7 +489,8 @@ impl BotInstance {
// println!("Privmsg section");
// Log::debug(&format!("Privmsg section"));
botlog::trace(
&format!("Privmsg section"),
// &format!("Privmsg section"),
"Privmsg section",
Some("BotInstance > runner()".to_string()),
Some(&msg),
);
@ -551,8 +538,9 @@ impl BotInstance {
}
pub async fn get_botmgrs(self) -> BotManagers {
let a = self.botmgrs;
a
// let a = self.botmgrs;
// a
self.botmgrs
}
pub fn get_identity(&self) -> Arc<RwLock<IdentityManager>> {
@ -560,19 +548,20 @@ impl BotInstance {
}
pub fn get_prefix(&self) -> char {
(*self).prefix
// (*self).prefix
self.prefix
}
// -----------------
// PRIVATE FUNCTIONS
pub async fn listener_main_prvmsg(bot: BotAR, msg: &PrivmsgMessage) -> () {
pub async fn listener_main_prvmsg(bot: BotAR, msg: &PrivmsgMessage) {
// println!(">> Inner listenermain_prvmsg()");
// Log::trace(">> Inner listenermain_prvmsg()");
botlog::trace(
">> Inner listenermain_prvmsg()",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
Some(msg),
);
// let a = a;
@ -589,7 +578,7 @@ impl BotInstance {
botlog::trace(
&format!("hacts size : {}", (*a).len()),
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
Some(msg),
);
// println!(">> Inner listenermain_prvmsg() >> before for loop of bot actions");
@ -597,16 +586,17 @@ impl BotInstance {
botlog::trace(
">> Inner listenermain_prvmsg() >> before for loop of bot actions",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
Some(msg),
);
for (_m, acts) in &*hacts.read().await {
// for (_m, acts) in &*hacts.read().await {
for acts in (*hacts.read().await).values() {
// println!(">> Inner listenermain_prvmsg() >> checking bot actions");
// Log::trace(">> Inner listenermain_prvmsg() >> checking bot actions");
botlog::trace(
">> Inner listenermain_prvmsg() >> checking bot actions",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
Some(msg),
);
// let bot = bot;
@ -617,10 +607,11 @@ impl BotInstance {
botlog::trace(
">> Inner listenermain_prvmsg() >> checking bot actions >> 2",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
Some(msg),
);
let _act = match a {
// let _act = match a {
match a {
crate::core::botmodules::BotAction::C(c) => {
/*
BotCommand handling -
@ -641,13 +632,13 @@ impl BotInstance {
botlog::trace(
"Reviewing internal commands",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
Some(msg),
);
// let inpt = msg.message_text.split("\n").next().expect("ERROR during BotCommand");
let inpt = msg
.message_text
.split(" ")
.split(' ')
.next()
.expect("ERROR during BotCommand");
@ -675,7 +666,8 @@ impl BotInstance {
botlog::debug(
"Confirmed bot command",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
// println!("Going for botlock");
@ -683,7 +675,8 @@ impl BotInstance {
botlog::trace(
"Going for botlock",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
let botlock = bot.read().await;
@ -692,7 +685,8 @@ impl BotInstance {
botlog::trace(
"Going for identity",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
let id = botlock.get_identity();
@ -704,11 +698,14 @@ impl BotInstance {
botlog::trace(
"Unpacking identity",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
// let (a, b) =
// id.can_user_run_prvmsg(&msg, c.required_roles.clone()).await;
let (a, b) =
id.can_user_run_PRVMSG(&msg, c.required_roles.clone()).await;
id.can_user_run_prvmsg(msg, c.required_roles.clone()).await;
// // [-] #todo : need ot add functionality around here to do an o7 when a mod has been promoted => Preferring to do this outside the mutex
// if let ChangeResult::Success(b) = b {
// // let b = b.to_lowercase();
@ -724,7 +721,8 @@ impl BotInstance {
botlog::trace(
"Checking if permissible",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
let (eval, rolechange) = eval;
@ -736,7 +734,8 @@ impl BotInstance {
botlog::notice(
"Assigning Mod UserRole to Mod",
Some("botinstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
// println!("Read() lock Bot");
@ -744,13 +743,15 @@ impl BotInstance {
botlog::trace(
"Read() lock Bot",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
let botlock = bot.read().await;
let outstr =
"o7 a Mod. I kneel to serve! pepeKneel ".to_string();
(*botlock).botmgrs.chat.say_in_reply_to(msg, outstr).await;
// (*botlock).botmgrs.chat.say_in_reply_to(msg, outstr).await;
botlock.botmgrs.chat.say_in_reply_to(msg, outstr).await;
}
}
@ -761,7 +762,8 @@ impl BotInstance {
botlog::debug(
"Executed as permissible",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
let a = Arc::clone(&bot);
c.execute(a, msg.clone()).await;
@ -770,7 +772,8 @@ impl BotInstance {
botlog::trace(
"exit out of execution",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
}
Permissible::Block => {
@ -779,7 +782,8 @@ impl BotInstance {
botlog::info(
"User Not allowed to run command",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
} // _ => (),
};
@ -803,7 +807,8 @@ impl BotInstance {
botlog::trace(
"End of Separate Listener Main prvmsg",
Some("BotInstance > listener_main_prvmsg()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
// self

View file

@ -5,23 +5,23 @@ use std::collections::HashMap;
use crate::core::identity;
use std::cell::RefCell;
// use std::cell::RefCell;
use std::sync::Arc;
use tokio::sync::RwLock;
use std::future::Future;
// use std::future::Future;
// use futures::lock::Mutex;
// Important to use tokios Mutex here since std Mutex doesn't work with async functions
use tokio::sync::Mutex;
// use tokio::sync::Mutex;
use crate::core::botinstance::{self, botlog, BotInstance};
use std::rc::Rc;
// use std::rc::Rc;
// use tokio::sync::RwLock;
use async_trait::async_trait;
use casual_logger::{Level, Log};
// use casual_logger::{Level, Log};
/*
@ -61,13 +61,13 @@ use botinstance::ChType;
use twitch_irc::message::PrivmsgMessage;
pub use ChType::Channel;
use self::bot_actions::actions_util;
// use self::bot_actions::actions_util;
use self::bot_actions::actions_util::BotAR;
#[derive(Debug)]
enum StatusLvl {
pub enum StatusLvl {
Instance,
Ch(ChType),
_Ch(ChType),
}
#[derive(Debug)]
@ -84,7 +84,7 @@ pub enum BotAction {
}
impl BotAction {
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) -> () {
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
match self {
BotAction::L(a) => a.execute(m, n).await,
BotAction::C(a) => a.execute(m, n).await,
@ -111,8 +111,9 @@ pub struct BotCommand {
}
impl BotCommand {
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) -> () {
((*self).exec_body)(m, n).await;
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
// ((*self).exec_body)(m, n).await;
(*self.exec_body)(m, n).await;
}
}
@ -138,10 +139,11 @@ pub mod bot_actions {
use std::future::Future;
use std::pin::Pin;
use std::rc::Rc;
// use std::rc::Rc;
use crate::core::botinstance::{BotInstance, BotManagers, Chat};
use std::cell::RefCell;
// use crate::core::botinstance::{BotInstance, BotManagers, Chat};
use crate::core::botinstance::BotInstance;
// use std::cell::RefCell;
use std::sync::Arc;
use twitch_irc::message::PrivmsgMessage;
// use futures::lock::Mutex;
@ -172,8 +174,9 @@ pub struct Listener {
}
impl Listener {
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) -> () {
((*self).exec_body)(m, n).await;
pub async fn execute(&self, m: BotAR, n: PrivmsgMessage) {
// ((*self).exec_body)(m, n).await;
(self.exec_body)(m, n).await;
}
}
@ -207,7 +210,7 @@ impl BotActionTrait for Listener {
}
#[derive(Debug)]
struct Routine {}
pub struct Routine {}
// #[derive(Clone)]
@ -235,7 +238,7 @@ impl ModulesManager {
let m = HashMap::new();
let act = HashMap::new();
let mut mgr = ModulesManager {
let mgr = ModulesManager {
statusdb: Arc::new(RwLock::new(m)),
botactions: Arc::new(RwLock::new(act)),
};
@ -392,13 +395,21 @@ impl ModulesManager {
// // () // return because there was a conflict?
// panic!("ERROR: Could not add {:?} ; there was a conflict with existing module {:?}", in_action , probmod );
// }
match find_conflict_module(&self, &in_action).await {
// Some(c) => panic!("ERROR: Could not add {:?} ; there was a conflict with existing module {:?}", in_action , c ),
Some(c) => panic!(
// match find_conflict_module(&self, &in_action).await {
// match find_conflict_module(self, &in_action).await {
// // Some(c) => panic!("ERROR: Could not add {:?} ; there was a conflict with existing module {:?}", in_action , c ),
// Some(c) => panic!(
// "ERROR: Could not add module; there was a conflict with existing module {:?}",
// c
// ),
// None => (),
// }
if let Some(c) = find_conflict_module(self, &in_action).await {
panic!(
"ERROR: Could not add module; there was a conflict with existing module {:?}",
c
),
None => (),
)
}
let mut dbt = self.statusdb.write().await;
@ -432,13 +443,12 @@ impl ModulesManager {
);
}
fn statuscleanup(&self, _: Option<ChType>) -> () {
fn _statuscleanup(&self, _: Option<ChType>) {
// internal cleans up statusdb . For example :
// - remove redudancies . If we see several Enabled("m"), only keep 1x
// - Clarify Conflict. If we see Enabled("m") and Disabled("m") , we remove Enabled("m") and keep Disabled("m")
// the IDEAL is that this is ran before every read/update operation to ensure quality
// Option<ChType> can pass Some(Channel("m")) (as an example) so statuscleanup only works on the given channel
// Passing None to chnl may be a heavy operation, as this will review and look at the whole table
()
}
}

View file

@ -1,25 +1,28 @@
use std::borrow::Borrow;
// use std::borrow::Borrow;
use std::collections::HashMap;
use std::error::Error;
// use std::error::Error;
use crate::core::botmodules::bot_actions::actions_util;
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
// use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager};
use crate::core::botinstance::{self, botlog, BotInstance, ChType};
use futures::lock::Mutex;
use twitch_irc::message::{Badge, PrivmsgMessage};
// use crate::core::botinstance::{self, botlog, BotInstance, ChType};
use crate::core::botinstance::{self, ChType};
// use futures::lock::Mutex;
// use twitch_irc::message::{Badge, PrivmsgMessage};
use twitch_irc::message::PrivmsgMessage;
// use crate::core::botmodules::ChType;
use crate::core::botinstance::ArcBox;
// use crate::core::botinstance::ArcBox;
use std::cell::RefCell;
use std::rc::Rc;
// use std::cell::RefCell;
// use std::rc::Rc;
use std::sync::Arc;
use tokio::sync::RwLock;
use casual_logger::{Level, Log};
use casual_logger::Log;
use super::botmodules::bot_actions::actions_util::BotAR;
@ -55,7 +58,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
async fn cmd_promote(bot: BotAR, msg: PrivmsgMessage) -> () {
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(
@ -99,7 +102,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let sendername = msg.clone().sender.name;
let mut argv = msg.message_text.split(" ");
let mut argv = msg.message_text.split(' ');
argv.next(); // Skip the command name
@ -142,7 +145,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let rslt = match targetusr {
Some(targetusr) => {
botinstance::botlog::debug(
&format!("running promote()"),
// &format!("running promote()"),
"running promote()",
Some("identity.rs > cmd_promote()".to_string()),
None,
);
@ -167,7 +171,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
None => {
botinstance::botlog::debug(
&format!("No Targer User argument"),
// &format!("No Targer User argument"),
"No Targer User argument",
Some("identity.rs > cmd_demote()".to_string()),
None,
);
@ -482,7 +487,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
*/
botinstance::botlog::trace(
&format!("End of cmd_promote()"),
// &format!("End of cmd_promote()"),
"End of cmd_promote()",
Some("identity.rs > cmd_prommote()".to_string()),
None,
);
@ -519,7 +525,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
tempb.add_to_modmgr(Arc::clone(&mgr)).await;
// async fn cmd_demote(mut _chat:Arc<Mutex<BotInstance>>,_msg:PrivmsgMessage) {
async fn cmd_demote(mut bot: BotAR, msg: PrivmsgMessage) {
async fn cmd_demote(bot: BotAR, msg: PrivmsgMessage) {
// println!("Called cmd demote");
botinstance::botlog::debug(
"Called cmd demote",
@ -566,8 +572,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// let arg2 = argv.next();
let (arg1, arg2) = {
let mut argv = msg.message_text.split(" ");
let (arg1, _arg2) = {
let mut argv = msg.message_text.split(' ');
argv.next(); // Skip the command name
@ -664,7 +670,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
let rslt = match targetusr {
Some(targetusr) => {
botinstance::botlog::debug(
&format!("running demote()"),
// &format!("running demote()"),
"running demote()",
Some("identity.rs > cmd_demote()".to_string()),
None,
);
@ -682,7 +689,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
None => {
botinstance::botlog::debug(
&format!("No Targer User argument"),
// &format!("No Targer User argument"),
"No Targer User argument",
Some("identity.rs > cmd_demote()".to_string()),
None,
);
@ -824,7 +832,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// println!("{}",msg.message_text);
let mut argv = msg.message_text.split(" ");
let mut argv = msg.message_text.split(' ');
// for v in argv {
// println!("args : {v}");
@ -971,7 +979,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&UserRole::SupMod(ChType::Channel(
targetchnl.to_lowercase().to_string(),
))) || callersproles.contains(&&UserRole::Broadcaster)
))) || callersproles.contains(&UserRole::Broadcaster)
{
idlock
.getspecialuserroles(
@ -1004,7 +1012,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
// # I believe at this stage I still have botlock active
botinstance::botlog::debug(
&format!("Evaluating special roles"),
// &format!("Evaluating special roles"),
"Evaluating special roles",
Some("identity.rs > init > getroles()".to_string()),
Some(&msg),
);
@ -1019,7 +1028,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|| (arg2.is_some() && arg2.unwrap() == targetuser.to_lowercase())
{
// First evaluates if they're broadcaster
let mut outmsg = format!("FeelsWowMan they're the broadcaster. ");
// let mut outmsg = format!("FeelsWowMan they're the broadcaster. ");
let mut outmsg = "FeelsWowMan they're the broadcaster. ".to_string();
if sproles.contains(&UserRole::Mod(ChType::Channel(
msg.channel_login.to_lowercase(),
))) || sproles.contains(&UserRole::SupMod(ChType::Channel(
@ -1037,7 +1047,8 @@ pub async fn init(mgr: Arc<ModulesManager>) {
{
format!("Target chatter's user roles are : {:?}", sproles)
} else {
format!("Target chatter has no special roles LULE ")
// format!("Target chatter has no special roles LULE ")
"Target chatter has no special roles LULE ".to_string()
};
// if sproles.contains(&UserRole::Mod(msg.channel_login.to_lowercase())) {
@ -1119,12 +1130,15 @@ pub enum Permissible {
Block,
}
type UserRolesDB = HashMap<String, Arc<RwLock<Vec<UserRole>>>>;
#[derive(Clone)]
pub struct IdentityManager {
// special_roles_users : HashMap<String,Vec<UserRole>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
// special_roles_users : Arc<Mutex<HashMap<String,Vec<UserRole>>>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
// special_roles_users : Arc<RwLock<HashMap<String,Vec<UserRole>>>>,
special_roles_users: Arc<RwLock<HashMap<String, Arc<RwLock<Vec<UserRole>>>>>>,
// special_roles_users: Arc<RwLock<HashMap<String, Arc<RwLock<Vec<UserRole>>>>>>,
special_roles_users: Arc<RwLock<UserRolesDB>>,
// parent_mgr : Box<crate::core::botinstance::BotManagers>,
//parent_mgr : Option<Box<crate::core::botinstance::BotManagers>>,
}
@ -1217,7 +1231,7 @@ impl IdentityManager {
// pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Result<Permissible,Box<dyn Error>>
// pub fn can_user_run_PRVMSG(&self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
// pub async fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
pub async fn can_user_run_PRVMSG(
pub async fn can_user_run_prvmsg(
&mut self,
msg: &PrivmsgMessage,
cmdreqroles: Vec<UserRole>,
@ -1229,7 +1243,8 @@ impl IdentityManager {
botinstance::botlog::debug(
"Checking within PRVMSG",
Some("identity.rs > can_user_run_PRVMSG()".to_string()),
Some(&msg),
// Some(&msg),
Some(msg),
);
let mut sender_badge: Option<ChatBadge> = None;
@ -1362,7 +1377,8 @@ impl IdentityManager {
let usr = usr.to_lowercase();
if cmdreqroles.len() == 0 {
// if cmdreqroles.len() == 0 {
if cmdreqroles.is_empty() {
// return Ok(Permissible::Allow)
return (
Permissible::Allow,
@ -1413,7 +1429,8 @@ impl IdentityManager {
None,
);
let roleslock = Arc::clone(&(*self).special_roles_users);
// let roleslock = Arc::clone(&(*self).special_roles_users);
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(
@ -1433,7 +1450,7 @@ impl IdentityManager {
// }
self.affirm_chatter_in_db(usr.clone()).await;
let mut roleslock = roleslock.write().await;
let roleslock = roleslock.write().await;
match (*roleslock).get(&usr.to_lowercase()) {
Some(usrroles)
if usrroles
@ -1470,7 +1487,7 @@ impl IdentityManager {
// Some("identity.rs > can_user_run()".to_string()), None);
let mut roleslock = roleslock;
let mut a = roleslock.get_mut(&usr.to_lowercase()).unwrap();
let a = roleslock.get_mut(&usr.to_lowercase()).unwrap();
let mut alock = a.write().await;
alock.push(UserRole::Mod(channelname.clone()));
@ -1513,7 +1530,12 @@ impl IdentityManager {
None,
);
if let Some(a) = (&*self)
// if let Some(a) = (&*self)
// .special_roles_users
// .read()
// .await
// .get(&usr.to_lowercase())
if let Some(a) = self
.special_roles_users
.read()
.await
@ -1546,7 +1568,12 @@ impl IdentityManager {
// [x] If cmdreqroles includes UserRole::SupMod("") , checks if chatter has UserRole::SupMod(channelname::ChType) to determine if Ok(Permissible::Allow)
if cmdreqroles.contains(&UserRole::SupMod(ChType::Channel(String::new()))) {
if let Some(a) = (&*self)
// if let Some(a) = (&*self)
// .special_roles_users
// .read()
// .await
// .get(&usr.to_lowercase())
if let Some(a) = self
.special_roles_users
.read()
.await
@ -1579,8 +1606,12 @@ impl IdentityManager {
botinstance::botlog::trace(
&format!(
"special roles get : {:?}",
(&*self)
.special_roles_users
// (&*self)
// .special_roles_users
// .read()
// .await
// .get(&usr.to_lowercase())
self.special_roles_users
.read()
.await
.get(&usr.to_lowercase())
@ -1589,7 +1620,8 @@ impl IdentityManager {
None,
);
if let Some(a) = (&*self)
// if let Some(a) = (&*self)
if let Some(a) = (self)
.special_roles_users
.read()
.await
@ -1701,7 +1733,7 @@ impl IdentityManager {
(authusrroles, trgusrroles)
} else {
let mut authusrroles = self
let authusrroles = self
.getspecialuserroles(authorizer.to_lowercase().clone(), None)
.await;
let trgusrroles = self
@ -1810,10 +1842,9 @@ impl IdentityManager {
.await;
return ChangeResult::Success(String::from("Promotion Successful"));
}
// Other else conditions would be mostly spcecial responses like ChangeResult::NoChange or ChangeResult::Fail
// related to authusrroles
else {
} else {
// Other else conditions would be mostly spcecial responses like ChangeResult::NoChange or ChangeResult::Fail
// related to authusrroles
return ChangeResult::Failed(String::from("You're not permitted to do that"));
}
} else if !trgusrroles.contains(&UserRole::Broadcaster)
@ -1893,8 +1924,13 @@ impl IdentityManager {
// At the moment, without any new roles, this should not be reached
// botinstance::botlog::warn(
// &format!("Code Warning : add handing for other trgusrroles"),
// Some("identity.rs > promote()".to_string()),
// None,
// );
botinstance::botlog::warn(
&format!("Code Warning : add handing for other trgusrroles"),
"Code Warning : add handing for other trgusrroles",
Some("identity.rs > promote()".to_string()),
None,
);
@ -2224,8 +2260,13 @@ impl IdentityManager {
// },
// _ => (),
// }
// botinstance::botlog::warn(
// &format!("Runtime reached undeveloped code"),
// Some("identity.rs > promote()".to_string()),
// None,
// );
botinstance::botlog::warn(
&format!("Runtime reached undeveloped code"),
"Runtime reached undeveloped code",
Some("identity.rs > promote()".to_string()),
None,
);
@ -2360,8 +2401,10 @@ 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(&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",
Some("identity.rs > demote()".to_string()), None);
Log::flush();
ChangeResult::Failed(String::from("Did not meet criteria to demote succesfully"))
}
@ -2477,7 +2520,8 @@ impl IdentityManager {
None,
);
return evalsproles;
// return evalsproles;
evalsproles
}
}

View file

@ -14,6 +14,12 @@ pub enum LimiterResp {
Skip, // as outside of rate limits
}
impl Default for RateLimiter {
fn default() -> Self {
Self::new()
}
}
impl RateLimiter {
pub fn new() -> Self {
Self {
@ -38,7 +44,7 @@ impl RateLimiter {
}
}
pub fn increment_counter(&mut self) -> () {
pub fn increment_counter(&mut self) {
self.msgcounter += 1;
}
}

View file

@ -2,12 +2,12 @@
// pub mod modules;
//use myLib;
//pub mod lib;
use std::process::Output;
// use std::process::Output;
// use crate::core::botinstance::ArcBox;
use botLib::core::botinstance::ArcBox;
// use bot_lib::core::botinstance::ArcBox;
use botLib::core::botinstance::{self, BotInstance};
use bot_lib::core::botinstance::{self, BotInstance};
// use core::botinstance::{self,BotInstance};
use casual_logger::Extension;
@ -33,10 +33,11 @@ pub async fn main() {
let a = a.read().await;
// let a = *a;
for (_, acts) in &*a {
// for (_, acts) in &*a {
for acts in (*a).values() {
for act in acts {
match act {
botLib::core::botmodules::BotAction::C(b) => {
bot_lib::core::botmodules::BotAction::C(b) => {
// println!("bot actiions: {}",b.command)
// Log::info(&format!("bot actions: {}",b.command));
botinstance::botlog::info(
@ -45,7 +46,7 @@ pub async fn main() {
None,
);
}
botLib::core::botmodules::BotAction::L(l) => {
bot_lib::core::botmodules::BotAction::L(l) => {
// println!("bot actiions: {}",l.name)
// Log::info(&format!("bot actions: {}",l.name));
botinstance::botlog::info(

View file

@ -10,7 +10,7 @@ pub use crate::core::botmodules::ModulesManager;
// use crate::core::botinstance;
pub use crate::core::botinstance::BotInstance;
use futures::lock::Mutex;
// use futures::lock::Mutex;
use std::sync::Arc;
// [ ] Load submodules

View file

@ -11,22 +11,23 @@
// mod crate::modules;
//use crate::modules;
use std::future::Future;
// use std::future::Future;
use crate::core::botmodules::bot_actions::actions_util::{self, BotAR};
use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, Listener, ModulesManager};
use crate::core::botinstance::{self, BotInstance, ChType};
use futures::lock::Mutex;
// use crate::core::botinstance::{self, BotInstance, ChType};
use crate::core::botinstance;
// use futures::lock::Mutex;
use twitch_irc::message::PrivmsgMessage;
use crate::core::identity;
use rand::Rng;
use std::rc::Rc;
// use std::rc::Rc;
use std::sync::{Arc, RwLock};
use std::sync::Arc;
// pub fn init(mgr:&mut ModulesManager)
pub async fn init(mgr: Arc<ModulesManager>) {
@ -63,7 +64,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
list1.add_to_modmgr(Arc::clone(&mgr)).await;
}
async fn good_girl(mut bot: BotAR, msg: PrivmsgMessage) {
async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
// println!("In GoodGirl() Listener");
// Change below from debug to trace if required later
botinstance::botlog::debug(