diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 0fb7f88..c5b7c07 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -145,9 +145,9 @@ impl Chat { -pub struct BotInstance -where - F: std::future::Future + ?Sized, +pub struct BotInstance +// where +// F: std::future::Future + ?Sized, { prefix : char, bot_channel : ChType, @@ -156,7 +156,7 @@ where // pub ratelimiters : HashMap, // used to limit messages sent per channel pub chat : Chat, // botmodules : HashMap>, - pub botmodules : ModulesManager, + pub botmodules : ModulesManager, twitch_oauth : String, pub bot_channels : Vec, /*bot_commands : Vec[BotCommand], @@ -168,15 +168,16 @@ where -impl BotInstance -where - F: std::future::Future + 'static, +impl BotInstance +// where +// F: std::future::Future + 'static, +// //F: 'static, { - pub fn init() -> BotInstance - where - F: std::future::Future + 'static, + pub fn init() -> BotInstance + // where + // F: std::future::Future + 'static, { dotenv().ok(); diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 2dc8671..f75831f 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -59,24 +59,24 @@ pub enum ModStatusType { // pub use EnType::Enabled; #[derive(Debug)] -pub enum BotAction -where - F: std::future::Future + ?Sized, +pub enum BotAction +// where +// F: std::future::Future + ?Sized, { //C(BotCommand), - L(Listener), + L(Listener), R(Routine), } -pub trait BotActionTrait -where - F: std::future::Future, +pub trait BotActionTrait +// where +// F: std::future::Future, { // 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); + fn add_to_bot(self, bot:BotInstance); + fn add_to_modmgr(self, modmgr:ModulesManager) -> ModulesManager; } @@ -173,51 +173,59 @@ where // } #[derive(Debug)] -pub struct Listener -where - F: std::future::Future, +pub struct Listener +// where +// F: std::future::Future + ?Sized, { pub module : ModType, pub name : String, //pub exec_body : fn(&mut BotInstance,&PrivmsgMessage) , - pub exec_body : fn(&mut Box>,&PrivmsgMessage) -> F , + // pub exec_body : fn(&mut Box>,&PrivmsgMessage) -> F , + //pub exec_body : fn(&mut botinstance::Chat,&PrivmsgMessage) -> F , + // pub exec_body : fn(botinstance::Chat,PrivmsgMessage) -> F , + //pub exec_body : fn(String,&PrivmsgMessage) -> F , pub help : String } -impl Listener -where - F: std::future::Future, +impl Listener +// where +// F: std::future::Future, { - async fn execute(&self,m:&mut Box>,n:&PrivmsgMessage){ + // async fn execute(&self,m:&mut Box>,n:&PrivmsgMessage){ + // async fn execute(&self,m:&mut botinstance::Chat,n:&PrivmsgMessage){ + async fn execute(&self,m:botinstance::Chat,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).await; + //(self.exec_body)(m,n).await; + // (self.exec_body)(m,n); } } -impl BotActionTrait for Listener -where - F: std::future::Future, +impl BotActionTrait for Listener +// where +// F: std::future::Future, { // fn add_to_bot(&self) -> Result> { // println!("Calling Add to Bot"); // Ok(String::from("Hello")) // } - fn add_to_bot(self, bot:BotInstance) { + 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 mgr = bot.botmodules; //let nmod = self.module.clone(); // mgr.add_botaction(self.module.clone(), BotAction::C(self)); - self.add_to_modmgr(&mut mgr); + self.add_to_modmgr(mgr); } - fn add_to_modmgr(self, modmgr:&mut ModulesManager) { + // fn add_to_modmgr(self, modmgr:&mut ModulesManager) { + //fn add_to_modmgr(self, mut modmgr:ModulesManager) { + fn add_to_modmgr(self, mut modmgr:ModulesManager) -> ModulesManager { // // let mut mgr = bot.botmodules; // // let nmod = self.module.clone(); // // mgr.add_botaction(nmod, BotAction::C(self)); @@ -226,7 +234,8 @@ where // 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)); + // modmgr.add_botaction(self.module.clone(), BotAction::L(self)); + 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 @@ -261,20 +270,23 @@ struct Routine {} #[derive(Debug)] -pub struct ModulesManager -where - F: std::future::Future, +pub struct ModulesManager +// where +// F: std::future::Future + ?Sized, { statusdb: HashMap>, - botactions: HashMap>>, + botactions: HashMap>, } -impl ModulesManager -where - F: std::future::Future, +impl ModulesManager +// where +// F: std::future::Future, { - pub fn init() -> ModulesManager { + pub fn init() -> ModulesManager + // where + // F: std::future::Future , + { // initializes the modulers manager // Ideally, this should have added known modules based on @@ -308,7 +320,7 @@ where // modactions.push(BotAction::L(newlistener)); - let mut mgr = ModulesManager { + let mgr = ModulesManager { statusdb : m, botactions : act, }; @@ -366,7 +378,7 @@ where // crate::core::init(); // works //crate::submods:: //crate::arbfile; - crate::modules::init(&mut mgr); + let mgr = crate::modules::init(mgr); @@ -400,8 +412,8 @@ where Ok("") } - - pub fn add_botaction(&mut self, in_module:ModType, in_action:BotAction ) -> () { + pub fn add_botaction(mut self, in_module:ModType, in_action:BotAction ) -> ModulesManager { + //pub fn add_botaction(&mut self, in_module:ModType, in_action:BotAction ) -> () { /* adds a BotAction to the Modules Manager - This will require a BotModule passed as well This will including the logic of a valid add @@ -429,9 +441,9 @@ where // - If BotAction to Add is a BotCommand , In Module Manager DB (botactions), // Check All Other BotAction Command Names & Aliases to ensure they don't conflict - fn find_conflict_module(mgr:& ModulesManager, act:& BotAction) -> Option - where - F: std::future::Future, + fn find_conflict_module(mgr:& ModulesManager, act:& BotAction) -> Option + // where + // F: std::future::Future, { // Some(BotModule(String::from("GambaCore"))) @@ -544,7 +556,12 @@ where println!(">> Modules Manager : Called Add bot Action"); //println!(">> Modules Manager : {:?}",&self); - (); + //(); + //let mgr = self; + + //mgr + + self } diff --git a/src/main.rs b/src/main.rs index c31f2fc..e001f36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,9 +24,9 @@ use crate::core::botinstance::BotInstance; #[tokio::main] pub async fn main() { - let bot:BotInstance> = BotInstance::init(); + // let bot:BotInstance> = BotInstance::init(); - //let bot = BotInstance::init(); + let bot = BotInstance::init(); bot.runner().await; diff --git a/src/modules.rs b/src/modules.rs index ddb87c1..f4cc19a 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -19,15 +19,14 @@ mod experiments; // [ ] init() function that accepts bot instance - this is passed to init() on submodules -pub fn init(mgr:&mut ModulesManager) -> () -where - F: std::future::Future, +pub fn init(mgr:ModulesManager) -> ModulesManager +// where +// F: std::future::Future, { // Modules initializer loads modules into the bot // this is achieved by calling submodules that also have fn init() defined - experiments::init(mgr); - + experiments::init(mgr) - (); + //(); } \ No newline at end of file diff --git a/src/modules/experiments.rs b/src/modules/experiments.rs index ae177ea..cc1d9bc 100644 --- a/src/modules/experiments.rs +++ b/src/modules/experiments.rs @@ -12,14 +12,14 @@ // mod crate::modules; //use crate::modules; -use crate::core::botmodules::{ModulesManager,Listener,BotModule,BotActionTrait}; +use crate::core::botmodules::{ModulesManager,Listener,BotModule,BotActionTrait, self}; -use crate::core::botinstance::BotInstance; +use crate::core::botinstance::{self}; use twitch_irc::message::PrivmsgMessage; -pub fn init(mgr:&mut ModulesManager) -> () -where - F: std::future::Future, +pub fn init(mgr:ModulesManager) -> ModulesManager +// where +// F: std::future::Future, { @@ -33,20 +33,87 @@ where // }.add_to_modmgr(mgr); - Listener { + let list1 = Listener { module : BotModule(String::from("experiments 004")), name : String::from("GoodGirl Listener"), - exec_body : good_girl, + // exec_body : good_girl::> , + // exec_body : good_girl , help : String::from("") - }.add_to_modmgr(mgr); + }; + + let mgr = list1.add_to_modmgr(mgr); + + // Listener { + // module : BotModule(String::from("experiments 004")), + // name : String::from("GoodGirl Listener"), + // // exec_body : good_girl::> , + // exec_body : good_girl , + // help : String::from("") + // }.add_to_modmgr(mgr); + + + // let list1 = Listener2 { + // module : BotModule(String::from("experiments 004")), + // name : String::from("GoodGirl Listener"), + // // exec_body : good_girl::> , + // exec_body : good_girl , + // help : String::from("") + // }; + + // let list1 = Listener3 { + // module : BotModule(String::from("experiments 004")), + // name : String::from("GoodGirl Listener"), + // // exec_body : good_girl::> , + // // exec_body : testfn2 , + // help : String::from("") + // }; println!("At Experiments module"); - (); + //(); + mgr } +pub struct Listener2 +// where +// F: std::future::Future + ?Sized, +{ + pub module : botmodules::ModType, + pub name : String, + //pub exec_body : fn(&mut BotInstance,&PrivmsgMessage) , + // pub exec_body : fn(&mut Box>,&PrivmsgMessage) -> F , + //pub exec_body : fn(&mut botinstance::Chat,&PrivmsgMessage) -> dyn std::future::Future , + pub exec_body : fn(&mut botinstance::Chat,&PrivmsgMessage) -> F , + //pub exec_body : fn(String,&PrivmsgMessage) -> F , + pub help : String +} + + +// pub struct Listener3 +// // where +// // F: std::future::Future + ?Sized, +// { +// pub module : botmodules::ModType, +// pub name : String, +// //pub exec_body : fn(&mut BotInstance,&PrivmsgMessage) , +// // pub exec_body : fn(&mut Box>,&PrivmsgMessage) -> F , +// //pub exec_body : fn(&mut botinstance::Chat,&PrivmsgMessage) -> dyn std::future::Future , +// // pub exec_body : fn(botinstance::Chat) -> F , // this appears to work +// // pub exec_body : fn(botinstance::Chat,PrivmsgMessage) -> F , // this appears to work +// //pub exec_body : fn(String,&PrivmsgMessage) -> F , +// pub help : String +// } + + +async fn testfn2(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) +// where +// F : std::future::Future + ?Sized, +{ + println!("testfn2"); +} + // async fn good_girl(bot:&mut BotInstance,msg:&PrivmsgMessage) { // println!("In GoodGirl()"); // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); @@ -72,16 +139,33 @@ where // } -async fn good_girl(bot:&mut Box>,msg:&PrivmsgMessage) - where - F: std::future::Future, +//async fn good_girl(bot:&mut Box>,msg:&PrivmsgMessage) +//async fn good_girl(chat:&mut botinstance::Chat,msg:&PrivmsgMessage) +// async fn good_girl(chat:&mut botinstance::Chat,msg:&PrivmsgMessage) +async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage) +// where +// F: std::future::Future + ?Sized, { 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; + chat.say_in_reply_to(&msg,String::from("GoodGirl")).await; } -} \ No newline at end of file +} + +// async fn good_girl(chat:String,msg:&PrivmsgMessage) +// // where +// // F: std::future::Future + ?Sized, +// { +// println!("In GoodGirl()"); +// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); + +// if msg.sender.name == "ModulatingForce" && msg.message_text.contains("GoodGirl") { +// println!("Testing from goodgirl"); +// } + + +// } \ No newline at end of file