From 25b73c41cce02cf9d5c833f8301fdd549bb45676 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:13:56 -0500 Subject: [PATCH] 2024.01.29 - Latest Compiles without issues --- src/core/botinstance.rs | 36 ++++++---- src/core/botmodules.rs | 141 +++++++++++++++++++++++++++---------- src/main.rs | 2 + src/modules.rs | 8 ++- src/modules/experiments.rs | 127 ++++++++++++++++++++++++--------- 5 files changed, 229 insertions(+), 85 deletions(-) diff --git a/src/core/botinstance.rs b/src/core/botinstance.rs index 32a64ae..fe66a2e 100644 --- a/src/core/botinstance.rs +++ b/src/core/botinstance.rs @@ -145,10 +145,13 @@ impl Chat { -pub struct BotInstance -where - // F: std::future::Future + ?Sized, - F: std::future::Future +// pub struct BotInstance +// where +// // F: std::future::Future + ?Sized, +// // F: std::future::Future, +// //F: std::future::Future + Send, +// F: Send + ?Sized, +pub struct BotInstance { prefix : char, bot_channel : ChType, @@ -157,7 +160,9 @@ where // pub ratelimiters : HashMap, // used to limit messages sent per channel pub chat : Chat, // botmodules : HashMap>, - pub botmodules : ModulesManager, + // pub botmodules : ModulesManager, + pub botmodules : ModulesManager, + //pub botmodules : &'static mut ModulesManager, twitch_oauth : String, pub bot_channels : Vec, /*bot_commands : Vec[BotCommand], @@ -169,16 +174,20 @@ where -impl BotInstance -where - F: std::future::Future + 'static, - //F: 'static, +// impl BotInstance +// where +// // F: std::future::Future + 'static, +// //F: 'static, +// //F: std::future::Future + Send + ?Sized 'static, +// F: Send + ?Sized + 'static, +impl BotInstance { - pub fn init() -> BotInstance - where - F: std::future::Future + 'static, + // pub fn init() -> BotInstance + // where + // F: std::future::Future + 'static, + pub fn init() -> BotInstance { dotenv().ok(); @@ -220,6 +229,8 @@ where + // let bm = &mut ModulesManager::init(); + let b = BotInstance { @@ -234,6 +245,7 @@ where // ratelimiters : ratelimiters, // used to limit messages sent per channel // botmodules : HashMap::new(), botmodules : ModulesManager::init(), + //botmodules : bm, twitch_oauth : oauth_token, bot_channels : botchannels, /*bot_commands : Vec[BotCommand], diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 67d44c7..a72ba5c 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -59,24 +59,37 @@ pub enum ModStatusType { // pub use EnType::Enabled; //#[derive(Debug)] -pub enum BotAction +// pub enum BotAction // where -// F: std::future::Future + ?Sized, +// //F: std::future::Future + ?Sized, +// // F: std::future::Future, +// //F: std::future::Future + Send, +// // F: Send, +// F: Send + ?Sized, +pub enum BotAction { //C(BotCommand), - L(Listener), + // L(Listener), + L(Listener), R(Routine), } -pub trait BotActionTrait -where - F: std::future::Future, +// pub trait BotActionTrait +// where +// // F: std::future::Future, +// //F: std::future::Future + ?Sized, +// //: std::future::Future + Send, +// // F: Send, +// F : Send + ?Sized +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:ModulesManager) -> ModulesManager; + fn add_to_bot(self, bot:BotInstance); + //fn add_to_modmgr(self, modmgr:ModulesManager) -> ModulesManager; + //fn add_to_modmgr(self,modmgr:&mut ModulesManager) -> ModulesManager; + fn add_to_modmgr(self,modmgr:&mut ModulesManager); } @@ -185,12 +198,26 @@ pub mod bot_actions { use crate::core::botinstance::Chat; use twitch_irc::message::PrivmsgMessage; - pub type ExecBody = Box Pin>>>; + // pub type ExecBody = Box Pin>>>; + + // 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 + // where + // //T: Future + 'static, + // //T: Future , + // T: Future + Send + 'static, + // { + // Box::new(move |a,b| Box::pin(f(a,b))) + // } + + pub fn asyncbox(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody where - T: Future + 'static, + //T: Future + 'static, //T: Future , + // T: Future + Send + 'static, + T: Future + Send + 'static, { Box::new(move |a,b| Box::pin(f(a,b))) } @@ -210,9 +237,14 @@ pub mod bot_actions { // } // #[derive(Debug)] -pub struct Listener +// pub struct Listener +pub struct Listener // where -// F: std::future::Future + ?Sized, +// // F: std::future::Future + ?Sized, +// //F: std::future::Future, +// //F: std::future::Future + ?Sized + Send, +// //F: Send, +// F: Send + ?Sized, { pub module : ModType, pub name : String, @@ -221,13 +253,17 @@ pub struct Listener //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 exec_body : bot_actions::actions_util::ExecBody, + //pub exec_body : bot_actions::actions_util::ExecBody, + pub exec_body : bot_actions::actions_util::ExecBody, pub help : String } -impl Listener +// impl Listener // where -// F: std::future::Future, +// // F: std::future::Future, +// //F: std::future::Future + Sized, +// F: std::future::Future + Sized + Send, +impl Listener { // async fn execute(&self,m:&mut Box>,n:&PrivmsgMessage){ @@ -241,29 +277,37 @@ impl Listener } } -impl BotActionTrait for Listener -where - F: std::future::Future, +// impl BotActionTrait for Listener +// where +// //F: std::future::Future, +// //F: std::future::Future + Sized, +// // F: std::future::Future + Send, +// // F : Send, +// F : Send + ?Sized, +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) { + // fn add_to_bot(self, mut bot:BotInstance) { + fn add_to_bot(self, mut bot:BotInstance) { // let mut mgr = bot.botmodules; // let nmod = self.module.clone(); // mgr.add_botaction(nmod, BotAction::C(self)); - let mgr = bot.botmodules; + //let mgr = &mut bot.botmodules; //let nmod = self.module.clone(); // mgr.add_botaction(self.module.clone(), BotAction::C(self)); + let mgr = &mut bot.botmodules; + self.add_to_modmgr(mgr); } - // 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 { + //fn add_to_modmgr(self, modmgr:&mut ModulesManager) -> ModulesManager { + fn add_to_modmgr(self, modmgr:&mut 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)); @@ -308,22 +352,33 @@ struct Routine {} //#[derive(Debug)] -pub struct ModulesManager +// pub struct ModulesManager // where -// F: std::future::Future + ?Sized, +// //F: std::future::Future + ?Sized, +// // F: std::future::Future, +// //F: std::future::Future + Send, +// // F: Send, +// // F: Send + ?Sized, +pub struct ModulesManager { statusdb: HashMap>, - botactions: HashMap>>, + botactions: HashMap>, } -impl ModulesManager +// impl ModulesManager // where -// F: std::future::Future, +// // F: std::future::Future, +// //F: std::future::Future + Send, +// // F : Send, +// F : Send + ?Sized, +impl ModulesManager { - pub fn init() -> ModulesManager + // pub fn init() -> ModulesManager // where // F: std::future::Future , + // pub fn init() -> &'static mut ModulesManager + pub fn init() -> ModulesManager { // initializes the modulers manager @@ -358,7 +413,11 @@ impl ModulesManager // modactions.push(BotAction::L(newlistener)); - let mgr = ModulesManager { + // let mgr = &mut ModulesManager { + // statusdb : m, + // botactions : act, + // }; + let mut mgr = ModulesManager { statusdb : m, botactions : act, }; @@ -416,14 +475,16 @@ impl ModulesManager // crate::core::init(); // works //crate::submods:: //crate::arbfile; - let mgr = crate::modules::init(mgr); + crate::modules::init(&mut mgr); println!(">> Modules Manager : End of Init"); //println!(">> Modules Manager : {:?}",mgr); - mgr + // let &mut mgr = mgr; + // &mgr + mgr } pub fn modstatus(&self, _:ModType, _:ChType) -> ModStatusType { @@ -450,8 +511,10 @@ impl ModulesManager Ok("") } - 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 ) -> ModulesManager { + // 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 ) -> () { + 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 @@ -479,9 +542,13 @@ impl ModulesManager // - 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 + // fn find_conflict_module(mgr:& ModulesManager, act:& BotAction) -> Option // where - // F: std::future::Future, + // // F: std::future::Future, + // // F: std::future::Future + Send, + // // F : Send, + // F : Send + ?Sized, + fn find_conflict_module(mgr:& ModulesManager, act:& BotAction) -> Option { // Some(BotModule(String::from("GambaCore"))) @@ -599,7 +666,7 @@ impl ModulesManager //mgr - self + //self } diff --git a/src/main.rs b/src/main.rs index ee7b3dc..0993cd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,8 @@ pub async fn main() { //let bot:BotInstance> = BotInstance::init(); + //let bot:BotInstance> = BotInstance::init(); + //let bot:BotInstance + Sized> = BotInstance::init(); let bot = BotInstance::init(); bot.runner().await; diff --git a/src/modules.rs b/src/modules.rs index c69fdd8..5fbaa8a 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -19,9 +19,13 @@ mod experiments; // [ ] init() function that accepts bot instance - this is passed to init() on submodules -pub fn init(mgr:ModulesManager) -> ModulesManager +// pub fn init(mgr:ModulesManager) -> ModulesManager +// pub fn init(mgr:ModulesManager) // where -// F: std::future::Future, +// // F: std::future::Future + Send, +// // F : Send, +// F : Send + ?Sized, +pub fn init(mgr:&mut ModulesManager) { // Modules initializer loads modules into the bot // this is achieved by calling submodules that also have fn init() defined diff --git a/src/modules/experiments.rs b/src/modules/experiments.rs index fba5427..c8ef785 100644 --- a/src/modules/experiments.rs +++ b/src/modules/experiments.rs @@ -12,14 +12,21 @@ // mod crate::modules; //use crate::modules; +use std::future::Future; + use crate::core::botmodules::{ModulesManager,Listener,BotModule,BotActionTrait, self}; +use crate::core::botmodules::bot_actions::actions_util; use crate::core::botinstance::{self}; use twitch_irc::message::PrivmsgMessage; -pub fn init(mgr:ModulesManager) -> ModulesManager +// pub fn init(mgr:ModulesManager) -> ModulesManager +// pub fn init(mgr:ModulesManager) // where -// F: std::future::Future, +// // F: std::future::Future + Send, +// // F : Send, +// F : Send + ?Sized, +pub fn init(mgr:&mut ModulesManager) { @@ -33,15 +40,64 @@ pub fn init(mgr:ModulesManager) -> ModulesManager // }.add_to_modmgr(mgr); - let list1 = Listener { - module : BotModule(String::from("experiments 004")), - name : String::from("GoodGirl Listener"), - // exec_body : good_girl::> , - // exec_body : good_girl , - help : String::from("") + // let list1 = 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 : actions_util::asyncbox(good_girl), + // //exec_body : actions_util::asyncbox(good_girl::>) , + // //exec_body : actions_util::asyncbox(good_girl::>), + + // help : String::from("") + // }; + + // let list1 = 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 : actions_util::asyncbox(good_girl), + // //exec_body : actions_util::asyncbox(good_girl::>) , + // //exec_body : actions_util::asyncbox(good_girl::>), + + // help : String::from("") + // }; + + //let list1 = 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 : actions_util::asyncbox(good_girl), + exec_body : actions_util::asyncbox(good_girl) , + //exec_body : actions_util::asyncbox(good_girl::>), + //exec_body : actions_util::asyncbox(good_girl::>>), + + help : String::from("") }; - let mgr = list1.add_to_modmgr(mgr); + + // let list1 = 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 : actions_util::asyncbox(good_girl), + // exec_body : actions_util::asyncbox(good_girl) , + // //exec_body : actions_util::asyncbox(good_girl::>), + + // help : String::from("") + // }; + + list1.add_to_modmgr(mgr); + + + // let mgr = list1.add_to_modmgr(mgr); // Listener { // module : BotModule(String::from("experiments 004")), @@ -68,27 +124,27 @@ pub fn init(mgr:ModulesManager) -> ModulesManager // help : String::from("") // }; - println!("At Experiments module"); + // println!("At Experiments module"); - //(); - mgr + // //(); + // 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 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 @@ -107,12 +163,12 @@ pub struct Listener2 // } -async fn testfn2(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) -// where -// F : std::future::Future + ?Sized, -{ - println!("testfn2"); -} +// 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()"); @@ -142,9 +198,12 @@ async fn testfn2(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) //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, +async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage) +//async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage) +// where +// //F: std::future::Future + ?Sized, +// //F: std::future::Future, +// F: std::future::Future + Sized + Send, { println!("In GoodGirl()"); println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);