diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 850d262..23f4a82 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -137,9 +137,9 @@ impl Chat { } - +#[derive(Clone)] pub struct BotManagers { - pub botmodules : ModulesManager, + // pub botmodules : ModulesManager, pub identity : IdentityManager, pub chat : Chat, } @@ -150,7 +150,7 @@ impl BotManagers { client:TwitchIRCClient, StaticLoginCredentials>) -> BotManagers { BotManagers { - botmodules : ModulesManager::init(), + // botmodules : ModulesManager::init(), identity : IdentityManager::init(), chat : Chat::init(ratelimiters,client), } @@ -166,7 +166,7 @@ pub struct BotInstance bot_channel : ChType, pub incoming_messages : UnboundedReceiver, // pub chat : Chat, - // pub botmodules : ModulesManager, + pub botmodules : ModulesManager, twitch_oauth : String, pub bot_channels : Vec, // pub identity : IdentityManager, @@ -234,7 +234,7 @@ impl BotInstance // ratelimiters : ratelimiters, // client : client, // } , - // botmodules : ModulesManager::init(), + botmodules : ModulesManager::init(), twitch_oauth : oauth_token, bot_channels : botchannels, // identity : IdentityManager::init(), @@ -304,13 +304,13 @@ impl BotInstance // async fn listener_main_prvmsg(&mut self,msg:PrivmsgMessage) -> () { - async fn listener_main_prvmsg(self,msg:&PrivmsgMessage) -> () { + async fn listener_main_prvmsg(&self,msg:&PrivmsgMessage) -> () { // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); // // [ ] Need to run through all Listener Bodies for Enabled Modules for the context of the message (e.g., ModStatus is Enabled in the context for the channel) - for (_m,acts) in &self.botmgrs.botmodules.botactions { + for (_m,acts) in &self.botmodules.botactions { for a in acts { match a { @@ -356,11 +356,11 @@ impl BotInstance // match self.botmgrs.identity.to_owned().can_user_run_PRVMSG(&msg, c.required_roles.clone()) { // match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) { - match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) { + match self.botmgrs.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone()) { // Ok(Permissible::Allow) => (), Permissible::Allow => { println!("Executed as permissible"); - c.execute(self.botmgrs.chat.clone(), msg.clone()).await; + c.execute(self.botmgrs.clone(), msg.clone()).await; } Permissible::Block => println!("User Not allowed to run command"), // _ => (), @@ -370,7 +370,7 @@ impl BotInstance } }, - crate::core::botmodules::BotAction::L(l) => l.execute(self.botmgrs.chat.clone(), msg.clone()).await, + crate::core::botmodules::BotAction::L(l) => l.execute(self.botmgrs.clone(), msg.clone()).await, _ => (), } diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index bdaba67..ab52696 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -66,7 +66,7 @@ pub enum BotAction } impl BotAction { - pub async fn execute(&self,m:botinstance::Chat,n:PrivmsgMessage){ + pub async fn execute(&self,m:botinstance::BotManagers,n:PrivmsgMessage){ match self { BotAction::L(a) => a.execute(m,n).await, @@ -96,7 +96,7 @@ pub struct BotCommand { impl BotCommand { - pub async fn execute(&self,m:botinstance::Chat,n:PrivmsgMessage){ + pub async fn execute(&self,m:botinstance::BotManagers,n:PrivmsgMessage){ (self.exec_body)(m,n).await; } } @@ -105,7 +105,7 @@ impl BotCommand impl BotActionTrait for BotCommand { fn add_to_bot(self, mut bot:BotInstance) { - let mgr = &mut bot.botmgrs.botmodules; + let mgr = &mut bot.botmodules; self.add_to_modmgr(mgr); } @@ -125,14 +125,16 @@ pub mod bot_actions { use std::boxed::Box; use std::pin::Pin; - use crate::core::botinstance::Chat; + use crate::core::botinstance::{BotManagers, Chat}; use twitch_irc::message::PrivmsgMessage; - pub type ExecBody = Box Pin + Send>> + Send + Sync>; + // pub type ExecBody = Box Pin + Send>> + Send + Sync>; //pub type ExecBody = Box Pin + Send>> + Send + Sync>; + pub type ExecBody = Box Pin + Send>> + Send + Sync>; //pub fn asyncbox(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody - pub fn asyncbox(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody + // pub fn asyncbox(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody + pub fn asyncbox(f: fn(BotManagers,PrivmsgMessage) -> T) -> ExecBody where T: Future + Send + 'static, { @@ -155,7 +157,7 @@ pub struct Listener impl Listener { - pub async fn execute(&self,m:botinstance::Chat,n:PrivmsgMessage){ + pub async fn execute(&self,m:botinstance::BotManagers,n:PrivmsgMessage){ (self.exec_body)(m,n).await; } } @@ -164,7 +166,7 @@ impl BotActionTrait for Listener { fn add_to_bot(self, mut bot:BotInstance) { - let mgr = &mut bot.botmgrs.botmodules; + let mgr = &mut bot.botmodules; self.add_to_modmgr(mgr); } diff --git a/src/core/identity.rs b/src/core/identity.rs index d1278b1..3424e14 100644 --- a/src/core/identity.rs +++ b/src/core/identity.rs @@ -32,7 +32,7 @@ pub fn init(mgr:&mut ModulesManager) ], }.add_to_modmgr(mgr); - async fn cmd_promote(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) { + async fn cmd_promote(mut _chat:botinstance::BotManagers,_msg:PrivmsgMessage) { //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); println!("Called cmd promote"); @@ -72,7 +72,7 @@ pub fn init(mgr:&mut ModulesManager) }.add_to_modmgr(mgr); - async fn cmd_demote(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) { + async fn cmd_demote(mut _chat:botinstance::BotManagers,_msg:PrivmsgMessage) { println!("Called cmd demote"); } @@ -101,7 +101,7 @@ pub enum Permissible { Block } -//#[derive(Clone)] +#[derive(Clone)] pub struct IdentityManager { special_roles_users : HashMap>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel // parent_mgr : Box, @@ -131,7 +131,7 @@ impl IdentityManager { // [ ] Maybe I should create a can_user_run version that simply takes PrvMsg, but then calls can_user_run directly // pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec) -> Result> - pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec) -> &Permissible + pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec) -> Permissible { // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); @@ -152,7 +152,11 @@ impl IdentityManager { // } if let Some(sender_badge) = sender_badge { - return &self.can_user_run(msg.sender.name.to_owned(), + // return &self.can_user_run(msg.sender.name.to_owned(), + // ChType::Channel(msg.channel_login.to_owned()), + // sender_badge, + // cmdreqroles + return self.can_user_run(msg.sender.name.to_owned(), ChType::Channel(msg.channel_login.to_owned()), sender_badge, cmdreqroles @@ -162,7 +166,7 @@ impl IdentityManager { // [ ] Call can_user_run() - &Permissible::Block + Permissible::Block } pub fn can_user_run(mut self, diff --git a/src/modules/experiments.rs b/src/modules/experiments.rs index 7f028fa..86e2a38 100644 --- a/src/modules/experiments.rs +++ b/src/modules/experiments.rs @@ -69,7 +69,7 @@ pub fn init(mgr:&mut ModulesManager) } -async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage) +async fn good_girl(mut bot:botinstance::BotManagers,msg:PrivmsgMessage) { println!("In GoodGirl()"); //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); @@ -88,9 +88,11 @@ async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage) { // chat.say_in_reply_to(&msg,String::from("GoodGirl")).await; //if rng.gen_ratio(1,5) { - let rollwin = rand::thread_rng().gen_ratio(1,10); + println!("In GoodGirl() > Pausechamp"); + let rollwin = rand::thread_rng().gen_ratio(1,5); if rollwin { - chat.say_in_reply_to(&msg,String::from("GoodGirl xdd ")).await; + println!("In GoodGirl() > Win"); + bot.chat.say_in_reply_to(&msg,String::from("GoodGirl xdd ")).await; } } @@ -100,7 +102,7 @@ async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage) } -async fn testy(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) +async fn testy(mut _chat:botinstance::BotManagers,_msg:PrivmsgMessage) { println!("testy triggered!")