2024.01.29 - Latest Compiles without issues

This commit is contained in:
ModulatingForce 2024-01-29 01:13:56 -05:00
parent b9ea781ed8
commit 25b73c41cc
5 changed files with 229 additions and 85 deletions

View file

@ -145,10 +145,13 @@ impl Chat {
pub struct BotInstance<F>
where
// F: std::future::Future + ?Sized,
F: std::future::Future
// pub struct BotInstance<F>
// 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<ChType,RateLimiter>, // used to limit messages sent per channel
pub chat : Chat,
// botmodules : HashMap<ModType,Vec<EnType>>,
pub botmodules : ModulesManager<F>,
// pub botmodules : ModulesManager<F>,
pub botmodules : ModulesManager,
//pub botmodules : &'static mut ModulesManager,
twitch_oauth : String,
pub bot_channels : Vec<ChType>,
/*bot_commands : Vec[BotCommand],
@ -169,16 +174,20 @@ where
impl<F> BotInstance<F>
where
F: std::future::Future + 'static,
//F: 'static,
// impl<F> BotInstance<F>
// 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<F>
where
F: std::future::Future + 'static,
// pub fn init() -> BotInstance<F>
// 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],

View file

@ -59,24 +59,37 @@ pub enum ModStatusType {
// pub use EnType::Enabled;
//#[derive(Debug)]
pub enum BotAction<F>
// pub enum BotAction<F>
// 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<F>),
// L(Listener<F>),
L(Listener),
R(Routine),
}
pub trait BotActionTrait<F>
where
F: std::future::Future,
// pub trait BotActionTrait<F>
// 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<String,Box<dyn Error>>;
fn add_to_bot(self, bot:BotInstance<F>);
fn add_to_modmgr(self, modmgr:ModulesManager<F>) -> ModulesManager<F>;
fn add_to_bot(self, bot:BotInstance);
//fn add_to_modmgr(self, modmgr:ModulesManager<F>) -> ModulesManager<F>;
//fn add_to_modmgr(self,modmgr:&mut ModulesManager<F>) -> ModulesManager<F>;
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<F> = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output = F>>>>;
// pub type ExecBody<F> = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output = F>>>>;
pub fn asyncbox<F, T>(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody<F>
// pub type ExecBody<F> = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output=F> + Send>> + Send + Sync>;
pub type ExecBody = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
// pub fn asyncbox<F, T>(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody<F>
// where
// //T: Future<Output = F> + 'static,
// //T: Future<Output = F> ,
// T: Future<Output=F> + Send + 'static,
// {
// Box::new(move |a,b| Box::pin(f(a,b)))
// }
pub fn asyncbox<T>(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody
where
T: Future<Output = F> + 'static,
//T: Future<Output = F> + 'static,
//T: Future<Output = F> ,
// T: Future<Output=F> + Send + 'static,
T: Future<Output=()> + 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<F>
// pub struct Listener<F>
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<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 exec_body : bot_actions::actions_util::ExecBody<F>,
//pub exec_body : bot_actions::actions_util::ExecBody<F>,
pub exec_body : bot_actions::actions_util::ExecBody,
pub help : String
}
impl<F> Listener<F>
// impl<F> Listener<F>
// 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<BotInstance<F>>,n:&PrivmsgMessage){
@ -241,29 +277,37 @@ impl<F> Listener<F>
}
}
impl<F> BotActionTrait<F> for Listener<F>
where
F: std::future::Future,
// impl<F> BotActionTrait<F> for Listener<F>
// 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<String,Box<dyn Error>> {
// println!("Calling Add to Bot");
// Ok(String::from("Hello"))
// }
fn add_to_bot(self, bot:BotInstance<F>) {
// fn add_to_bot(self, mut bot:BotInstance<F>) {
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<F>) {
//fn add_to_modmgr(self, mut modmgr:ModulesManager) {
fn add_to_modmgr(self, mut modmgr:ModulesManager<F>) -> ModulesManager<F> {
//fn add_to_modmgr(self, modmgr:&mut ModulesManager<F>) -> ModulesManager<F> {
fn add_to_modmgr(self, modmgr:&mut ModulesManager) {
//fn add_to_modmgr(self, mut modmgr:ModulesManager<F>) -> ModulesManager<F> {
// // 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<F>
// pub struct ModulesManager<F>
// 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<ModType,Vec<ModStatusType>>,
botactions: HashMap<ModType,Vec<BotAction<F>>>,
botactions: HashMap<ModType,Vec<BotAction>>,
}
impl<F> ModulesManager<F>
// impl<F> ModulesManager<F>
// 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<F>
// pub fn init() -> ModulesManager<F>
// where
// F: std::future::Future ,
// pub fn init() -> &'static mut ModulesManager
pub fn init() -> ModulesManager
{
// initializes the modulers manager
@ -358,7 +413,11 @@ impl<F> ModulesManager<F>
// 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,13 +475,15 @@ impl<F> ModulesManager<F>
// 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);
// let &mut mgr = mgr;
// &mgr
mgr
}
@ -450,8 +511,10 @@ impl<F> ModulesManager<F>
Ok("")
}
pub fn add_botaction(mut self, in_module:ModType, in_action:BotAction<F> ) -> ModulesManager<F> {
//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<F> ) -> ModulesManager<F> {
//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<F> ModulesManager<F>
// - 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<F>(mgr:& ModulesManager<F>, act:& BotAction<F>) -> Option<ModType>
// fn find_conflict_module<F>(mgr:& ModulesManager<F>, act:& BotAction<F>) -> Option<ModType>
// 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<ModType>
{
// Some(BotModule(String::from("GambaCore")))
@ -599,7 +666,7 @@ impl<F> ModulesManager<F>
//mgr
self
//self
}

View file

@ -26,6 +26,8 @@ pub async fn main() {
//let bot:BotInstance<dyn std::future::Future<Output = ()>> = BotInstance::init();
//let bot:BotInstance<dyn Send + std::future::Future<Output = ()>> = BotInstance::init();
//let bot:BotInstance<std::future::Future<Output = ()> + Sized> = BotInstance::init();
let bot = BotInstance::init();
bot.runner().await;

View file

@ -19,9 +19,13 @@ mod experiments;
// [ ] init() function that accepts bot instance - this is passed to init() on submodules
pub fn init<F>(mgr:ModulesManager<F>) -> ModulesManager<F>
// pub fn init<F>(mgr:ModulesManager<F>) -> ModulesManager<F>
// pub fn init<F>(mgr:ModulesManager<F>)
// 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

View file

@ -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<F>(mgr:ModulesManager<F>) -> ModulesManager<F>
// pub fn init<F>(mgr:ModulesManager<F>) -> ModulesManager<F>
// pub fn init<F>(mgr:ModulesManager<F>)
// 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<F>(mgr:ModulesManager<F>) -> ModulesManager<F>
// }.add_to_modmgr(mgr);
// let list1 = Listener::<dyn std::future::Future<Output = ()>> {
// //let list1 = Listener {
// module : BotModule(String::from("experiments 004")),
// name : String::from("GoodGirl Listener"),
// // exec_body : good_girl::<dyn std::future::Future<Output = ()>> ,
// // exec_body : good_girl ,
// exec_body : actions_util::asyncbox(good_girl),
// //exec_body : actions_util::asyncbox(good_girl::<dyn std::future::Future<Output = ()>>) ,
// //exec_body : actions_util::asyncbox(good_girl::<dyn std::future::Future<Output = ()>>),
// help : String::from("")
// };
// let list1 = Listener::<dyn std::future::Future<Output = ()>> {
// //let list1 = Listener {
// module : BotModule(String::from("experiments 004")),
// name : String::from("GoodGirl Listener"),
// // exec_body : good_girl::<dyn std::future::Future<Output = ()>> ,
// // exec_body : good_girl ,
// exec_body : actions_util::asyncbox(good_girl),
// //exec_body : actions_util::asyncbox(good_girl::<dyn std::future::Future<Output = ()>>) ,
// //exec_body : actions_util::asyncbox(good_girl::<dyn std::future::Future<Output = ()>>),
// help : String::from("")
// };
//let list1 = Listener::<dyn Send + std::future::Future<Output = ()>> {
let list1 = Listener {
module : BotModule(String::from("experiments 004")),
name : String::from("GoodGirl Listener"),
// exec_body : good_girl::<dyn std::future::Future<Output = ()>> ,
//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::<dyn std::future::Future<Output = ()>>),
//exec_body : actions_util::asyncbox(good_girl::<dyn std::future::Future<Output = dyn Future<Output = ()>>>),
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::<dyn std::future::Future<Output = ()>> ,
// //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::<dyn std::future::Future<Output = ()>>),
// 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<F>(mgr:ModulesManager<F>) -> ModulesManager<F>
// help : String::from("")
// };
println!("At Experiments module");
// println!("At Experiments module");
//();
mgr
// //();
// mgr
}
pub struct Listener2<F>
// 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<BotInstance<F>>,&PrivmsgMessage) -> F ,
//pub exec_body : fn(&mut botinstance::Chat,&PrivmsgMessage) -> dyn std::future::Future<Output = ()> ,
pub exec_body : fn(&mut botinstance::Chat,&PrivmsgMessage) -> F ,
//pub exec_body : fn(String,&PrivmsgMessage) -> F ,
pub help : String
}
// pub struct Listener2<F>
// // 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<BotInstance<F>>,&PrivmsgMessage) -> F ,
// //pub exec_body : fn(&mut botinstance::Chat,&PrivmsgMessage) -> dyn std::future::Future<Output = ()> ,
// pub exec_body : fn(&mut botinstance::Chat,&PrivmsgMessage) -> F ,
// //pub exec_body : fn(String,&PrivmsgMessage) -> F ,
// pub help : String
// }
// pub struct Listener3<F>
@ -107,12 +163,12 @@ pub struct Listener2<F>
// }
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()");
@ -143,8 +199,11 @@ async fn testfn2(mut _chat:botinstance::Chat,_msg:PrivmsgMessage)
//async fn good_girl<F>(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)
//async fn good_girl<F>(mut chat:botinstance::Chat,msg:PrivmsgMessage)
// where
// F: std::future::Future + ?Sized,
// //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);