From a697f1d477f69d7503a9d1fcc7b479cf5b6a6407 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Tue, 26 Dec 2023 20:00:32 -0500 Subject: [PATCH] 2023.12.26_latest_problem_setup --- src/core/botinstance.rs | 2 +- src/core/botmodules.rs | 141 ++++++++++++++++++++++++++++++++++--- src/modules/experiments.rs | 48 +++++++++++-- 3 files changed, 174 insertions(+), 17 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index fbb8545..eb9eadf 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -151,7 +151,7 @@ pub struct BotInstance { //pub client : TwitchIRCClient,StaticLoginCredentials>, pub incoming_messages : UnboundedReceiver, // pub ratelimiters : HashMap, // used to limit messages sent per channel - chat : Chat, + pub chat : Chat, // botmodules : HashMap>, pub botmodules : ModulesManager, twitch_oauth : String, diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 9dc1e2a..3aba55d 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -39,6 +39,7 @@ pub enum ChType { pub use ChType::Channel; +use twitch_irc::message::PrivmsgMessage; use crate::core::botinstance::{self, BotInstance}; @@ -63,18 +64,61 @@ pub enum BotAction { L(Listener), R(Routine), } + + +pub trait BotActionTrait { + // async fn execute(&self,m:&mut BotInstance,n:&PrivmsgMessage); + // fn add_to_bot(self, bot:BotInstance) -> Result>; + fn add_to_bot(self, bot:BotInstance); + fn add_to_modmgr(self, modmgr:&mut ModulesManager); +} + + #[derive(Debug)] pub struct BotCommand { pub module : ModType, pub command : String, // command call name pub alias : Vec, // String of alternative names // bot_prefix : char, // although should be global? - // exec_body : fn, + exec_body : fn(&BotInstance,&PrivmsgMessage), pub help : String, } impl BotCommand { - pub fn add_to_bot(self, bot:BotInstance) { + // pub fn add_to_bot(self, bot:BotInstance) { + // // let mut mgr = bot.botmodules; + // // let nmod = self.module.clone(); + // // mgr.add_botaction(nmod, BotAction::C(self)); + // let mut mgr = bot.botmodules; + // //let nmod = self.module.clone(); + // // mgr.add_botaction(self.module.clone(), BotAction::C(self)); + + // self.add_to_modmgr(&mut mgr); + // } + + + // pub fn add_to_modmgr(self, modmgr:&mut ModulesManager) { + // // // let mut mgr = bot.botmodules; + // // // let nmod = self.module.clone(); + // // // mgr.add_botaction(nmod, BotAction::C(self)); + // // let mut mgr = modmgr; + // // //let nmod = self.module.clone(); + // // mgr.add_botaction(self.module.clone(), BotAction::C(self)); + // // let mut mgr = modmgr; + // // //let nmod = self.module.clone(); + // modmgr.add_botaction(self.module.clone(), BotAction::C(self)); + // } + + +} + +impl BotActionTrait for BotCommand { + // fn add_to_bot(&self) -> Result> { + // println!("Calling Add to Bot"); + // Ok(String::from("Hello")) + // } + + fn add_to_bot(self, bot:BotInstance) { // let mut mgr = bot.botmodules; // let nmod = self.module.clone(); // mgr.add_botaction(nmod, BotAction::C(self)); @@ -85,8 +129,7 @@ impl BotCommand { self.add_to_modmgr(&mut mgr); } - - pub fn add_to_modmgr(self, modmgr:&mut ModulesManager) { + fn add_to_modmgr(self, modmgr:&mut ModulesManager) { // // let mut mgr = bot.botmodules; // // let nmod = self.module.clone(); // // mgr.add_botaction(nmod, BotAction::C(self)); @@ -98,17 +141,97 @@ impl BotCommand { modmgr.add_botaction(self.module.clone(), BotAction::C(self)); } + // => 12.23 - MF: NOTE : The exec body is defined ad module level , not this core level + // fn exec_body(&self,m:&BotInstance,n:&PrivmsgMessage){ + // // => 12.23 - [ ] #todo requires field + // // (&self.exec)(String::from("Hello from BotAction Trait")) + // //self.exec_body(m,n) + // } + + // fn execute(&self,m:&mut BotInstance,n:&PrivmsgMessage){ + // // => 12.23 - [ ] #todo requires field + // // (&self.exec)(String::from("Hello from BotAction Trait")) + // //self.exec_body(m,n) + // (self.exec_body)(m,n) + // } } + #[derive(Debug)] -struct Listener { - module : ModType, - name : String, - // exec_body : fn, - help : String +pub struct Listener { + pub module : ModType, + pub name : String, + pub exec_body : fn(&mut BotInstance,&PrivmsgMessage) , + pub help : String } +impl Listener { + + async fn execute(&self,m:&mut BotInstance,n:&PrivmsgMessage){ + // => 12.23 - [ ] #todo requires field + // (&self.exec)(String::from("Hello from BotAction Trait")) + //self.exec_body(m,n) + (self.exec_body)(m,n) + } +} + +impl BotActionTrait for Listener { + // fn add_to_bot(&self) -> Result> { + // println!("Calling Add to Bot"); + // Ok(String::from("Hello")) + // } + + fn add_to_bot(self, bot:BotInstance) { + // let mut mgr = bot.botmodules; + // let nmod = self.module.clone(); + // mgr.add_botaction(nmod, BotAction::C(self)); + let mut mgr = bot.botmodules; + //let nmod = self.module.clone(); + // mgr.add_botaction(self.module.clone(), BotAction::C(self)); + + self.add_to_modmgr(&mut mgr); + } + + fn add_to_modmgr(self, modmgr:&mut ModulesManager) { + // // let mut mgr = bot.botmodules; + // // let nmod = self.module.clone(); + // // mgr.add_botaction(nmod, BotAction::C(self)); + // let mut mgr = modmgr; + // //let nmod = self.module.clone(); + // mgr.add_botaction(self.module.clone(), BotAction::C(self)); + // let mut mgr = modmgr; + // //let nmod = self.module.clone(); + modmgr.add_botaction(self.module.clone(), BotAction::L(self)); + } + + // => 12.23 - MF: NOTE : The exec body is defined ad module level , not this core level + + // fn exec_body(&self,m:&BotInstance,n:&PrivmsgMessage){ + // // => 12.23 - [ ] #todo requires field + // // (&self.exec)(String::from("Hello from BotAction Trait")) + // //self.exec_body(m,n) + // } + + // fn execute(&self,m:&mut BotInstance,n:&PrivmsgMessage){ + // // => 12.23 - [ ] #todo requires field + // // (&self.exec)(String::from("Hello from BotAction Trait")) + // //self.exec_body(m,n) + // (self.exec_body)(m,n) + // } + + + // // => 12.23 - MF : There are issues trying to define async at trait level + // async fn execute(&self,m:&mut BotInstance,n:&PrivmsgMessage) -> Result<>{ + // // => 12.23 - [ ] #todo requires field + // // (&self.exec)(String::from("Hello from BotAction Trait")) + // //self.exec_body(m,n) + // (self.exec_body)(m,n) + // } +} + + + #[derive(Debug)] struct Routine {} diff --git a/src/modules/experiments.rs b/src/modules/experiments.rs index 756883b..94d9fdb 100644 --- a/src/modules/experiments.rs +++ b/src/modules/experiments.rs @@ -12,22 +12,56 @@ // mod crate::modules; //use crate::modules; -use crate::core::botmodules::{ModulesManager,BotCommand,BotModule}; +use crate::core::botmodules::{ModulesManager,BotCommand,Listener,BotModule,BotActionTrait}; + +use crate::core::botinstance::BotInstance; +use twitch_irc::message::PrivmsgMessage; pub fn init(mgr:&mut ModulesManager) -> () { - BotCommand { + // BotCommand { + // module : BotModule(String::from("experiments 004")), + // command : String::from("DUPCMD4"), // command call name + // alias : vec![String::from("DUPALIAS4A"),String::from("DUPALIAS4B")], // String of alternative names + // // bot_prefix : char, // although should be global? + // // exec_body : fn, + // help : String::from("DUPCMD4 tester"), + // }.add_to_modmgr(mgr); + + + Listener { module : BotModule(String::from("experiments 004")), - command : String::from("DUPCMD4"), // command call name - alias : vec![String::from("DUPALIAS4A"),String::from("DUPALIAS4B")], // String of alternative names - // bot_prefix : char, // although should be global? - // exec_body : fn, - help : String::from("DUPCMD4 tester"), + name : String::from("GoodGirl Listener"), + exec_body : good_girl, + help : String::from("") }.add_to_modmgr(mgr); println!("At Experiments module"); (); +} + + +// async fn good_girl(bot:&mut BotInstance,msg:&PrivmsgMessage) { +// println!("In GoodGirl()"); +// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); + +// if msg.sender.name == "ModulatingForce" && msg.message_text.contains("GoodGirl") { +// bot.chat.say_in_reply_to(msg,String::from("GoodGirl")); +// } + +// () +// } + + async fn good_girl(bot:&mut BotInstance,msg:&PrivmsgMessage) { + println!("In GoodGirl()"); + println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); + + if msg.sender.name == "ModulatingForce" && msg.message_text.contains("GoodGirl") { + bot.chat.say_in_reply_to(msg,String::from("GoodGirl")).await; + } + + } \ No newline at end of file