2023.12.26_latest_problem_setup

This commit is contained in:
ModulatingForce 2023-12-26 20:00:32 -05:00
parent 31f4924acf
commit a697f1d477
3 changed files with 174 additions and 17 deletions

View file

@ -151,7 +151,7 @@ pub struct BotInstance {
//pub client : TwitchIRCClient<TCPTransport<TLS>,StaticLoginCredentials>, //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 ratelimiters : HashMap<ChType,RateLimiter>, // used to limit messages sent per channel
chat : Chat, pub chat : Chat,
// botmodules : HashMap<ModType,Vec<EnType>>, // botmodules : HashMap<ModType,Vec<EnType>>,
pub botmodules : ModulesManager, pub botmodules : ModulesManager,
twitch_oauth : String, twitch_oauth : String,

View file

@ -39,6 +39,7 @@ pub enum ChType {
pub use ChType::Channel; pub use ChType::Channel;
use twitch_irc::message::PrivmsgMessage;
use crate::core::botinstance::{self, BotInstance}; use crate::core::botinstance::{self, BotInstance};
@ -63,18 +64,61 @@ pub enum BotAction {
L(Listener), L(Listener),
R(Routine), R(Routine),
} }
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_modmgr(self, modmgr:&mut ModulesManager);
}
#[derive(Debug)] #[derive(Debug)]
pub struct BotCommand { pub struct BotCommand {
pub module : ModType, pub module : ModType,
pub command : String, // command call name pub command : String, // command call name
pub alias : Vec<String>, // String of alternative names pub alias : Vec<String>, // String of alternative names
// bot_prefix : char, // although should be global? // bot_prefix : char, // although should be global?
// exec_body : fn, exec_body : fn(&BotInstance,&PrivmsgMessage),
pub help : String, pub help : String,
} }
impl BotCommand { 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<String,Box<dyn Error>> {
// println!("Calling Add to Bot");
// Ok(String::from("Hello"))
// }
fn add_to_bot(self, bot:BotInstance) {
// let mut mgr = bot.botmodules; // let mut mgr = bot.botmodules;
// let nmod = self.module.clone(); // let nmod = self.module.clone();
// mgr.add_botaction(nmod, BotAction::C(self)); // mgr.add_botaction(nmod, BotAction::C(self));
@ -85,8 +129,7 @@ impl BotCommand {
self.add_to_modmgr(&mut mgr); self.add_to_modmgr(&mut mgr);
} }
fn add_to_modmgr(self, modmgr:&mut ModulesManager) {
pub fn add_to_modmgr(self, modmgr:&mut ModulesManager) {
// // let mut mgr = bot.botmodules; // // let mut mgr = bot.botmodules;
// // let nmod = self.module.clone(); // // let nmod = self.module.clone();
// // mgr.add_botaction(nmod, BotAction::C(self)); // // mgr.add_botaction(nmod, BotAction::C(self));
@ -98,17 +141,97 @@ impl BotCommand {
modmgr.add_botaction(self.module.clone(), BotAction::C(self)); 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)] #[derive(Debug)]
struct Listener { pub struct Listener {
module : ModType, pub module : ModType,
name : String, pub name : String,
// exec_body : fn, pub exec_body : fn(&mut BotInstance,&PrivmsgMessage) ,
help : String 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<String,Box<dyn Error>> {
// 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)] #[derive(Debug)]
struct Routine {} struct Routine {}

View file

@ -12,18 +12,29 @@
// mod crate::modules; // mod crate::modules;
//use 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) -> () { 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")), module : BotModule(String::from("experiments 004")),
command : String::from("DUPCMD4"), // command call name name : String::from("GoodGirl Listener"),
alias : vec![String::from("DUPALIAS4A"),String::from("DUPALIAS4B")], // String of alternative names exec_body : good_girl,
// bot_prefix : char, // although should be global? help : String::from("")
// exec_body : fn,
help : String::from("DUPCMD4 tester"),
}.add_to_modmgr(mgr); }.add_to_modmgr(mgr);
println!("At Experiments module"); println!("At Experiments module");
@ -31,3 +42,26 @@ pub fn init(mgr:&mut ModulesManager) -> () {
(); ();
} }
// 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;
}
}