comments cleanup
This commit is contained in:
parent
0472e56856
commit
3585c1ec9b
4 changed files with 13 additions and 583 deletions
|
@ -16,19 +16,9 @@ use std::collections::HashMap;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
|
|
||||||
//mod sub::ratelimiter;
|
|
||||||
|
|
||||||
use crate::core::ratelimiter::RateLimiter;
|
use crate::core::ratelimiter::RateLimiter;
|
||||||
use crate::core::ratelimiter;
|
use crate::core::ratelimiter;
|
||||||
// use crate::core::ratelimiter;
|
|
||||||
|
|
||||||
// pub fn init() -> ()
|
|
||||||
// {
|
|
||||||
// println!("I was here");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// use crate::core::botmodules::BotAction
|
|
||||||
|
|
||||||
|
|
||||||
use crate::core::botmodules;
|
use crate::core::botmodules;
|
||||||
use crate::core::botmodules::ModulesManager;
|
use crate::core::botmodules::ModulesManager;
|
||||||
|
@ -47,20 +37,6 @@ pub enum ModType {
|
||||||
|
|
||||||
pub use ModType::BotModule;
|
pub use ModType::BotModule;
|
||||||
|
|
||||||
// pub enum EnType {
|
|
||||||
// Enabled(ChType),
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub use EnType::Enabled;
|
|
||||||
|
|
||||||
// pub enum ModStatusType {
|
|
||||||
// Enabled(EnType),
|
|
||||||
// Disabled(EnType),
|
|
||||||
// Enabled(ModType),
|
|
||||||
// Disabled(ModType),
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Chat {
|
pub struct Chat {
|
||||||
pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
|
pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
|
||||||
|
@ -78,10 +54,14 @@ impl Chat {
|
||||||
|
|
||||||
|
|
||||||
pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () {
|
pub async fn say_in_reply_to(&mut self, msg:& PrivmsgMessage , mut outmsg:String) -> () {
|
||||||
// envelops a message before sending a message
|
/*
|
||||||
// [x] This could include additional formatting (e.g., add in random number of blank spaces)
|
formats message before sending to TwitchIRC
|
||||||
// [x] Incrementing or checking with RateLimiters
|
|
||||||
// [ ] For BotActions of Enabled Modules , checking whether the caller is Permissible to run the command ?
|
- [x] Custom String Formatting (e.g., adding random black spaces)
|
||||||
|
- [x] Ratelimiter Handling
|
||||||
|
- [ ] Checkf if BotActions is Enabled & Caller is Allowed to Run
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
// self.client.say_in_reply_to(msg,outmsg).await.unwrap();
|
// self.client.say_in_reply_to(msg,outmsg).await.unwrap();
|
||||||
|
|
||||||
|
@ -148,48 +128,23 @@ impl Chat {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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
|
pub struct BotInstance
|
||||||
{
|
{
|
||||||
prefix : char,
|
prefix : char,
|
||||||
bot_channel : ChType,
|
bot_channel : ChType,
|
||||||
//pub client : TwitchIRCClient<TCPTransport<TLS>,StaticLoginCredentials>,
|
|
||||||
pub incoming_messages : UnboundedReceiver<ServerMessage>,
|
pub incoming_messages : UnboundedReceiver<ServerMessage>,
|
||||||
// pub ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
|
|
||||||
pub chat : Chat,
|
pub chat : Chat,
|
||||||
// botmodules : HashMap<ModType,Vec<EnType>>,
|
|
||||||
// pub botmodules : ModulesManager<F>,
|
|
||||||
pub botmodules : ModulesManager,
|
pub botmodules : ModulesManager,
|
||||||
//pub botmodules : &'static mut ModulesManager,
|
|
||||||
twitch_oauth : String,
|
twitch_oauth : String,
|
||||||
pub bot_channels : Vec<ChType>,
|
pub bot_channels : Vec<ChType>,
|
||||||
/*bot_commands : Vec[BotCommand],
|
|
||||||
bot_listeners : Vec[Listener],
|
|
||||||
bot_routines : Vec[Routine],*/
|
|
||||||
// botactionsdb : botactionsdb:botactions,
|
|
||||||
// identity : identitymodule,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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
|
impl BotInstance
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// pub fn init() -> BotInstance<F>
|
|
||||||
// where
|
|
||||||
// F: std::future::Future + 'static,
|
|
||||||
pub fn init() -> BotInstance
|
pub fn init() -> BotInstance
|
||||||
{
|
{
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
@ -245,17 +200,9 @@ impl BotInstance
|
||||||
ratelimiters : ratelimiters,
|
ratelimiters : ratelimiters,
|
||||||
client : client,
|
client : client,
|
||||||
} ,
|
} ,
|
||||||
// ratelimiters : ratelimiters, // used to limit messages sent per channel
|
|
||||||
// botmodules : HashMap::new(),
|
|
||||||
botmodules : ModulesManager::init(),
|
botmodules : ModulesManager::init(),
|
||||||
//botmodules : bm,
|
|
||||||
twitch_oauth : oauth_token,
|
twitch_oauth : oauth_token,
|
||||||
bot_channels : botchannels,
|
bot_channels : botchannels,
|
||||||
/*bot_commands : Vec[BotCommand],
|
|
||||||
bot_listeners : Vec[Listener],
|
|
||||||
bot_routines : Vec[Routine],*/
|
|
||||||
// botactionsdb : botactionsdb:botactions,
|
|
||||||
// identity : identitymodule,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -316,54 +263,6 @@ impl BotInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// pub async fn run(mut self) -> () {
|
|
||||||
|
|
||||||
// let join_handle = tokio::spawn(async move {
|
|
||||||
|
|
||||||
// while let Some(message) = self.incoming_messages.recv().await {
|
|
||||||
// // Below can be used to debug if I want to capture all messages
|
|
||||||
// // println!("Received message: {:?}", message);
|
|
||||||
|
|
||||||
// match message {
|
|
||||||
// ServerMessage::Notice(msg) => {
|
|
||||||
// if let Some(chnl) = msg.channel_login {
|
|
||||||
// println!("NOTICE : (#{}) {}", chnl, msg.message_text);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ServerMessage::Privmsg(msg) => {
|
|
||||||
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
|
||||||
|
|
||||||
// println!("Privmsg section");
|
|
||||||
|
|
||||||
// // b.listener_main_prvmsg(&msg);
|
|
||||||
// self.listener_main_prvmsg(&msg).await;
|
|
||||||
// // - BotCommand listener should likely need to be called within the above
|
|
||||||
|
|
||||||
|
|
||||||
// },
|
|
||||||
// ServerMessage::Whisper(msg) => {
|
|
||||||
// println!("(w) {}: {}", msg.sender.name, msg.message_text);
|
|
||||||
// },
|
|
||||||
// ServerMessage::Join(msg) => {
|
|
||||||
// println!("JOINED: {}", msg.channel_login);
|
|
||||||
// },
|
|
||||||
// ServerMessage::Part(msg) => {
|
|
||||||
// println!("PARTED: {}", msg.channel_login);
|
|
||||||
// },
|
|
||||||
// _ => {}
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// join_handle.await.unwrap();
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// PRIVATE FUNCTIONS
|
// PRIVATE FUNCTIONS
|
||||||
|
|
||||||
|
@ -372,37 +271,6 @@ impl BotInstance
|
||||||
|
|
||||||
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||||
|
|
||||||
|
|
||||||
// // // let contextratelimiter = ratelimiters.get_mut(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
|
|
||||||
// let contextratelimiter = self.ratelimiters
|
|
||||||
// .get_mut(&Channel(String::from(&msg.channel_login)))
|
|
||||||
// .expect("ERROR: Issue with Rate limiters");
|
|
||||||
// // let contextratelimiter = self.ratelimiters.get(&msg.channel_login).expect("ERROR: Issue with Rate limiters");
|
|
||||||
|
|
||||||
// match contextratelimiter.check_limiter() {
|
|
||||||
// ratelimiter::LimiterResp::Allow => {
|
|
||||||
// let maxblanks = rand::thread_rng().gen_range(1..=20);
|
|
||||||
// //let mut outmsg = "GotTrolled ".to_owned();
|
|
||||||
// let mut outmsg = "annytfLurk ".to_owned();
|
|
||||||
|
|
||||||
// for _i in 1..maxblanks {
|
|
||||||
// let blankspace: &str = "";
|
|
||||||
// outmsg.push_str(blankspace);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // client.say_in_reply_to(&msg,outmsg).await.unwrap();
|
|
||||||
// self.client.say_in_reply_to(msg,outmsg).await.unwrap();
|
|
||||||
// println!("(#{}) > {}", msg.channel_login, "rate limit counter increase");
|
|
||||||
// contextratelimiter.increment_counter();
|
|
||||||
// println!("{:?}",self.ratelimiters);
|
|
||||||
// },
|
|
||||||
// ratelimiter::LimiterResp::Skip => {
|
|
||||||
// (); // do nothing otherwise
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// self.chat.say_in_reply_to(msg,String::from("annytfLurk")).await;
|
|
||||||
|
|
||||||
// // [ ] 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)
|
// // [ ] 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.botmodules.botactions {
|
for (_m,acts) in &self.botmodules.botactions {
|
||||||
|
|
|
@ -56,20 +56,9 @@ pub enum ModStatusType {
|
||||||
Disabled(StatusLvl),
|
Disabled(StatusLvl),
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub use EnType::Enabled;
|
|
||||||
|
|
||||||
//#[derive(Debug)]
|
|
||||||
// pub enum BotAction<F>
|
|
||||||
// where
|
|
||||||
// //F: std::future::Future + ?Sized,
|
|
||||||
// // F: std::future::Future,
|
|
||||||
// //F: std::future::Future + Send,
|
|
||||||
// // F: Send,
|
|
||||||
// F: Send + ?Sized,
|
|
||||||
pub enum BotAction
|
pub enum BotAction
|
||||||
{
|
{
|
||||||
//C(BotCommand),
|
//C(BotCommand),
|
||||||
// L(Listener<F>),
|
|
||||||
L(Listener),
|
L(Listener),
|
||||||
R(Routine),
|
R(Routine),
|
||||||
}
|
}
|
||||||
|
@ -81,26 +70,13 @@ impl BotAction {
|
||||||
BotAction::L(a) => a.execute(m,n).await,
|
BotAction::L(a) => a.execute(m,n).await,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
// (self.exec_body)(m,n).await;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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
|
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);
|
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);
|
fn add_to_modmgr(self,modmgr:&mut ModulesManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,16 +167,6 @@ pub trait BotActionTrait
|
||||||
|
|
||||||
pub mod bot_actions {
|
pub mod bot_actions {
|
||||||
|
|
||||||
// use std::boxed::Box;
|
|
||||||
// use std::pin::Pin;
|
|
||||||
// use std::future::Future;
|
|
||||||
|
|
||||||
// use crate::core::botinstance::Chat;
|
|
||||||
// use twitch_irc::message::PrivmsgMessage;
|
|
||||||
|
|
||||||
|
|
||||||
// type ExecBody<F> = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output = F>>>>;
|
|
||||||
|
|
||||||
pub mod actions_util {
|
pub mod actions_util {
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
@ -210,27 +176,10 @@ pub mod bot_actions {
|
||||||
use crate::core::botinstance::Chat;
|
use crate::core::botinstance::Chat;
|
||||||
use twitch_irc::message::PrivmsgMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
|
|
||||||
// pub type ExecBody<F> = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output = F>>>>;
|
pub type ExecBody = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
|
||||||
|
|
||||||
// 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 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
|
pub fn asyncbox<T>(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody
|
||||||
//pub fn asyncbox<T>(f: fn(Chat,&PrivmsgMessage) -> T) -> ExecBody
|
|
||||||
where
|
where
|
||||||
//T: Future<Output = F> + 'static,
|
|
||||||
//T: Future<Output = F> ,
|
|
||||||
// T: Future<Output=F> + Send + 'static,
|
|
||||||
T: Future<Output=()> + Send + 'static,
|
T: Future<Output=()> + Send + 'static,
|
||||||
{
|
{
|
||||||
Box::new(move |a,b| Box::pin(f(a,b)))
|
Box::new(move |a,b| Box::pin(f(a,b)))
|
||||||
|
@ -242,121 +191,34 @@ pub mod bot_actions {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #[derive(Debug)]
|
|
||||||
// pub struct Listener {
|
|
||||||
// pub module : ModType,
|
|
||||||
// pub name : String,
|
|
||||||
// pub exec_body : fn(&mut BotInstance,&PrivmsgMessage) ,
|
|
||||||
// pub help : String
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[derive(Debug)]
|
|
||||||
// pub struct Listener<F>
|
|
||||||
pub struct Listener
|
pub struct Listener
|
||||||
// where
|
|
||||||
// // F: std::future::Future + ?Sized,
|
|
||||||
// //F: std::future::Future,
|
|
||||||
// //F: std::future::Future + ?Sized + Send,
|
|
||||||
// //F: Send,
|
|
||||||
// F: Send + ?Sized,
|
|
||||||
{
|
{
|
||||||
pub module : ModType,
|
pub module : ModType,
|
||||||
pub name : String,
|
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) -> 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,
|
pub exec_body : bot_actions::actions_util::ExecBody,
|
||||||
pub help : String
|
pub help : String
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<F> Listener<F>
|
|
||||||
// where
|
|
||||||
// // F: std::future::Future,
|
|
||||||
// //F: std::future::Future + Sized,
|
|
||||||
// F: std::future::Future + Sized + Send,
|
|
||||||
impl Listener
|
impl Listener
|
||||||
{
|
{
|
||||||
|
|
||||||
// async fn execute(&self,m:&mut Box<BotInstance<F>>,n:&PrivmsgMessage){
|
|
||||||
// async fn execute(&self,m:&mut botinstance::Chat,n:&PrivmsgMessage){
|
|
||||||
pub async fn execute(&self,m:botinstance::Chat,n:PrivmsgMessage){
|
pub 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<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
|
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, mut bot:BotInstance<F>) {
|
|
||||||
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 = &mut bot.botmodules;
|
|
||||||
//let nmod = self.module.clone();
|
|
||||||
// mgr.add_botaction(self.module.clone(), BotAction::C(self));
|
|
||||||
|
|
||||||
let mgr = &mut bot.botmodules;
|
let mgr = &mut bot.botmodules;
|
||||||
|
|
||||||
self.add_to_modmgr(mgr);
|
self.add_to_modmgr(mgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//fn add_to_modmgr(self, modmgr:&mut ModulesManager<F>) -> ModulesManager<F> {
|
|
||||||
fn add_to_modmgr(self, modmgr:&mut ModulesManager) {
|
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));
|
|
||||||
// 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));
|
|
||||||
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
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -364,140 +226,35 @@ impl BotActionTrait for Listener
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Routine {}
|
struct Routine {}
|
||||||
|
|
||||||
|
|
||||||
//#[derive(Debug)]
|
|
||||||
// pub struct ModulesManager<F>
|
|
||||||
// where
|
|
||||||
// //F: std::future::Future + ?Sized,
|
|
||||||
// // F: std::future::Future,
|
|
||||||
// //F: std::future::Future + Send,
|
|
||||||
// // F: Send,
|
|
||||||
// // F: Send + ?Sized,
|
|
||||||
pub struct ModulesManager
|
pub struct ModulesManager
|
||||||
{
|
{
|
||||||
statusdb: HashMap<ModType,Vec<ModStatusType>>,
|
statusdb: HashMap<ModType,Vec<ModStatusType>>,
|
||||||
pub botactions: HashMap<ModType,Vec<BotAction>>,
|
pub botactions: HashMap<ModType,Vec<BotAction>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<F> ModulesManager<F>
|
|
||||||
// where
|
|
||||||
// // F: std::future::Future,
|
|
||||||
// //F: std::future::Future + Send,
|
|
||||||
// // F : Send,
|
|
||||||
// F : Send + ?Sized,
|
|
||||||
impl ModulesManager
|
impl ModulesManager
|
||||||
{
|
{
|
||||||
|
|
||||||
// pub fn init() -> ModulesManager<F>
|
|
||||||
// where
|
|
||||||
// F: std::future::Future ,
|
|
||||||
// pub fn init() -> &'static mut ModulesManager
|
|
||||||
pub fn init() -> ModulesManager
|
pub fn init() -> ModulesManager
|
||||||
{
|
{
|
||||||
|
|
||||||
// initializes the modulers manager
|
|
||||||
// Ideally, this should have added known modules based on
|
|
||||||
// directory structure and API user recommendations
|
|
||||||
|
|
||||||
let mut m = HashMap::new();
|
let m = HashMap::new();
|
||||||
let mut act = HashMap::new();
|
let act = HashMap::new();
|
||||||
|
|
||||||
// -- some processing including adding into the hashmap
|
|
||||||
|
|
||||||
// let newmodule = BotModule(String::from("GambaCore"));
|
|
||||||
|
|
||||||
// let newlistener = Listener {
|
|
||||||
// module : BotModule(String::from("experiments").to_owned()),
|
|
||||||
// name : String::from("socklistener"),
|
|
||||||
// help : String::from("This will listen and react to sock randomly"),
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
// // As a Demonstration, the listener's Module is added and Enabled at Instance level
|
|
||||||
// let statusvector = m
|
|
||||||
// .entry(BotModule(String::from("experiments")))
|
|
||||||
// .or_insert(Vec::new());
|
|
||||||
|
|
||||||
// statusvector.push(ModStatusType::Enabled(StatusLvl::Instance));
|
|
||||||
|
|
||||||
// let modactions = act
|
|
||||||
// .entry( BotModule(String::from("experiments")))
|
|
||||||
// .or_insert(Vec::new());
|
|
||||||
|
|
||||||
// modactions.push(BotAction::L(newlistener));
|
|
||||||
|
|
||||||
|
|
||||||
// let mgr = &mut ModulesManager {
|
|
||||||
// statusdb : m,
|
|
||||||
// botactions : act,
|
|
||||||
// };
|
|
||||||
let mut mgr = ModulesManager {
|
let mut mgr = ModulesManager {
|
||||||
statusdb : m,
|
statusdb : m,
|
||||||
botactions : act,
|
botactions : act,
|
||||||
};
|
};
|
||||||
|
|
||||||
// // -- This area can be where bot actions are imported to the bot's module manager
|
|
||||||
|
|
||||||
// // -- Below can be used to validate what occurs when dup BotCommands are added
|
// initialize custom crate modules
|
||||||
|
|
||||||
// let bcmd = BotCommand {
|
|
||||||
// module : BotModule(String::from("experiments 001")),
|
|
||||||
// command : String::from("DUPCMD1"), // command call name
|
|
||||||
// alias : vec![String::from("DUPALIAS1A"),String::from("DUPALIAS1B")], // String of alternative names
|
|
||||||
// // bot_prefix : char, // although should be global?
|
|
||||||
// // exec_body : fn,
|
|
||||||
// help : String::from("DUPCMD1 tester"),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// mgr.add_botaction(BotModule(String::from("experiments 001")), BotAction::C(bcmd));
|
|
||||||
|
|
||||||
|
|
||||||
// let bcmd = BotCommand {
|
|
||||||
// module : BotModule(String::from("experiments 002")),
|
|
||||||
// command : String::from("DUPCMD2"), // command call name
|
|
||||||
// alias : vec![String::from("DUPALIAS2A"),String::from("DUPALIAS2B")], // String of alternative names
|
|
||||||
// // bot_prefix : char, // although should be global?
|
|
||||||
// // exec_body : fn,
|
|
||||||
// help : String::from("DUPCMD2 tester"),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// mgr.add_botaction(BotModule(String::from("experiments 002")), BotAction::C(bcmd));
|
|
||||||
|
|
||||||
// -- Below working demonstration of BotCommand.add_to_modmgr()
|
|
||||||
|
|
||||||
// BotCommand {
|
|
||||||
// module : BotModule(String::from("experiments 003")),
|
|
||||||
// command : String::from("DUPCMD3"), // command call name
|
|
||||||
// alias : vec![String::from("DUPALIAS3A"),String::from("DUPALIAS3B")], // String of alternative names
|
|
||||||
// // bot_prefix : char, // although should be global?
|
|
||||||
// // exec_body : fn,
|
|
||||||
// help : String::from("DUPCMD3 tester"),
|
|
||||||
// }.add_to_modmgr(&mut mgr);
|
|
||||||
|
|
||||||
// crate::core::botmodules::BotCommand{
|
|
||||||
// module : BotModule(String::from("experiments 003")),
|
|
||||||
// command : String::from("DUPCMD3"), // command call name
|
|
||||||
// alias : vec![String::from("DUPALIAS3A"),String::from("DUPALIAS3B")], // String of alternative names
|
|
||||||
// // bot_prefix : char, // although should be global?
|
|
||||||
// // exec_body : fn,
|
|
||||||
// help : String::from("DUPCMD3 tester"),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// // => 2023.12.22 - [x] MF : How can I call submods:init() ?
|
|
||||||
// // => 2023.12.22 - this was answered - needed to pub modules in main.rs
|
|
||||||
// crate::core::botinstance::init(); // works
|
|
||||||
// crate::core::init(); // works
|
|
||||||
//crate::submods::
|
|
||||||
//crate::arbfile;
|
|
||||||
crate::modules::init(&mut mgr);
|
crate::modules::init(&mut mgr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
println!(">> Modules Manager : End of Init");
|
println!(">> Modules Manager : End of Init");
|
||||||
//println!(">> Modules Manager : {:?}",mgr);
|
|
||||||
|
|
||||||
// let &mut mgr = mgr;
|
|
||||||
// &mgr
|
|
||||||
mgr
|
mgr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,12 +313,6 @@ impl ModulesManager
|
||||||
// - If BotAction to Add is a BotCommand , In Module Manager DB (botactions),
|
// - 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
|
// 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>
|
|
||||||
// where
|
|
||||||
// // F: std::future::Future,
|
|
||||||
// // F: std::future::Future + Send,
|
|
||||||
// // F : Send,
|
|
||||||
// F : Send + ?Sized,
|
|
||||||
fn find_conflict_module(mgr:& ModulesManager, act:& BotAction) -> Option<ModType>
|
fn find_conflict_module(mgr:& ModulesManager, act:& BotAction) -> Option<ModType>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -1,20 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
// use twitch_irc::login::StaticLoginCredentials;
|
|
||||||
// use twitch_irc::ClientConfig;
|
|
||||||
// use twitch_irc::SecureTCPTransport;
|
|
||||||
// use twitch_irc::TwitchIRCClient;
|
|
||||||
// use twitch_irc::message::ServerMessage;
|
|
||||||
// use std::env;
|
|
||||||
// // use std::time::Instant;
|
|
||||||
// use rand::Rng;
|
|
||||||
// use dotenv::dotenv;
|
|
||||||
// // mod helpers;
|
|
||||||
|
|
||||||
// use std::collections::HashMap;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod modules;
|
pub mod modules;
|
||||||
use std::process::Output;
|
use std::process::Output;
|
||||||
|
@ -24,10 +9,6 @@ use crate::core::botinstance::BotInstance;
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn main() {
|
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();
|
let bot = BotInstance::init();
|
||||||
|
|
||||||
bot.runner().await;
|
bot.runner().await;
|
||||||
|
|
|
@ -20,12 +20,6 @@ use crate::core::botmodules::bot_actions::actions_util;
|
||||||
use crate::core::botinstance::{self};
|
use crate::core::botinstance::{self};
|
||||||
use twitch_irc::message::PrivmsgMessage;
|
use twitch_irc::message::PrivmsgMessage;
|
||||||
|
|
||||||
// pub fn init<F>(mgr:ModulesManager<F>) -> ModulesManager<F>
|
|
||||||
// pub fn init<F>(mgr:ModulesManager<F>)
|
|
||||||
// where
|
|
||||||
// // F: std::future::Future + Send,
|
|
||||||
// // F : Send,
|
|
||||||
// F : Send + ?Sized,
|
|
||||||
pub fn init(mgr:&mut ModulesManager)
|
pub fn init(mgr:&mut ModulesManager)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -40,170 +34,20 @@ pub fn init(mgr:&mut ModulesManager)
|
||||||
// }.add_to_modmgr(mgr);
|
// }.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 {
|
let list1 = Listener {
|
||||||
module : BotModule(String::from("experiments 004")),
|
module : BotModule(String::from("experiments 004")),
|
||||||
name : String::from("GoodGirl Listener"),
|
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) ,
|
||||||
//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("")
|
help : String::from("")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
list1.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::<dyn std::future::Future<Output = ()>> ,
|
|
||||||
// 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::<dyn std::future::Future<Output = ()>> ,
|
|
||||||
// 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::<dyn std::future::Future<Output = ()>> ,
|
|
||||||
// // exec_body : testfn2 ,
|
|
||||||
// help : String::from("")
|
|
||||||
// };
|
|
||||||
|
|
||||||
// println!("At Experiments module");
|
|
||||||
|
|
||||||
|
|
||||||
// //();
|
|
||||||
// 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 Listener3<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(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);
|
|
||||||
|
|
||||||
// if msg.sender.name == "ModulatingForce" && msg.message_text.contains("GoodGirl") {
|
|
||||||
// bot.chat.say_in_reply_to(msg,String::from("GoodGirl"));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async fn good_girl<F>(bot:&mut BotInstance<F>,msg:&PrivmsgMessage)
|
|
||||||
// where
|
|
||||||
// F: std::future::Future,
|
|
||||||
// {
|
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
//async fn good_girl<F>(bot:&mut Box<BotInstance<F>>,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(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,
|
|
||||||
// F: std::future::Future + Sized + Send,
|
|
||||||
{
|
{
|
||||||
println!("In GoodGirl()");
|
println!("In GoodGirl()");
|
||||||
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
|
||||||
|
@ -214,17 +58,3 @@ async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
Loading…
Reference in a new issue