Working - BotManagers Added

This commit is contained in:
ModulatingForce 2024-01-31 18:36:23 -05:00
parent be2e967e40
commit f8b9cefacb
4 changed files with 36 additions and 28 deletions

View file

@ -137,9 +137,9 @@ impl Chat {
} }
#[derive(Clone)]
pub struct BotManagers { pub struct BotManagers {
pub botmodules : ModulesManager, // pub botmodules : ModulesManager,
pub identity : IdentityManager, pub identity : IdentityManager,
pub chat : Chat, pub chat : Chat,
} }
@ -150,7 +150,7 @@ impl BotManagers {
client:TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>) client:TwitchIRCClient<TCPTransport<TLS>, StaticLoginCredentials>)
-> BotManagers { -> BotManagers {
BotManagers { BotManagers {
botmodules : ModulesManager::init(), // botmodules : ModulesManager::init(),
identity : IdentityManager::init(), identity : IdentityManager::init(),
chat : Chat::init(ratelimiters,client), chat : Chat::init(ratelimiters,client),
} }
@ -166,7 +166,7 @@ pub struct BotInstance
bot_channel : ChType, bot_channel : ChType,
pub incoming_messages : UnboundedReceiver<ServerMessage>, pub incoming_messages : UnboundedReceiver<ServerMessage>,
// pub chat : Chat, // pub chat : Chat,
// pub botmodules : ModulesManager, pub botmodules : ModulesManager,
twitch_oauth : String, twitch_oauth : String,
pub bot_channels : Vec<ChType>, pub bot_channels : Vec<ChType>,
// pub identity : IdentityManager, // pub identity : IdentityManager,
@ -234,7 +234,7 @@ impl BotInstance
// ratelimiters : ratelimiters, // ratelimiters : ratelimiters,
// client : client, // client : client,
// } , // } ,
// botmodules : ModulesManager::init(), botmodules : ModulesManager::init(),
twitch_oauth : oauth_token, twitch_oauth : oauth_token,
bot_channels : botchannels, bot_channels : botchannels,
// identity : IdentityManager::init(), // identity : IdentityManager::init(),
@ -304,13 +304,13 @@ impl BotInstance
// async fn listener_main_prvmsg(&mut self,msg:PrivmsgMessage) -> () { // async fn listener_main_prvmsg(&mut self,msg:PrivmsgMessage) -> () {
async fn listener_main_prvmsg(self,msg:&PrivmsgMessage) -> () { async fn listener_main_prvmsg(&self,msg:&PrivmsgMessage) -> () {
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
// // [ ] 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.botmgrs.botmodules.botactions { for (_m,acts) in &self.botmodules.botactions {
for a in acts { for a in acts {
match a { match a {
@ -356,11 +356,11 @@ impl BotInstance
// match self.botmgrs.identity.to_owned().can_user_run_PRVMSG(&msg, c.required_roles.clone()) { // match self.botmgrs.identity.to_owned().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) { // match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
match self.botmgrs.identity.can_user_run_PRVMSG(&msg, c.required_roles.clone()) { match self.botmgrs.identity.clone().can_user_run_PRVMSG(&msg, c.required_roles.clone()) {
// Ok(Permissible::Allow) => (), // Ok(Permissible::Allow) => (),
Permissible::Allow => { Permissible::Allow => {
println!("Executed as permissible"); println!("Executed as permissible");
c.execute(self.botmgrs.chat.clone(), msg.clone()).await; c.execute(self.botmgrs.clone(), msg.clone()).await;
} }
Permissible::Block => println!("User Not allowed to run command"), Permissible::Block => println!("User Not allowed to run command"),
// _ => (), // _ => (),
@ -370,7 +370,7 @@ impl BotInstance
} }
}, },
crate::core::botmodules::BotAction::L(l) => l.execute(self.botmgrs.chat.clone(), msg.clone()).await, crate::core::botmodules::BotAction::L(l) => l.execute(self.botmgrs.clone(), msg.clone()).await,
_ => (), _ => (),
} }

View file

@ -66,7 +66,7 @@ pub enum BotAction
} }
impl BotAction { impl BotAction {
pub async fn execute(&self,m:botinstance::Chat,n:PrivmsgMessage){ pub async fn execute(&self,m:botinstance::BotManagers,n:PrivmsgMessage){
match self { match self {
BotAction::L(a) => a.execute(m,n).await, BotAction::L(a) => a.execute(m,n).await,
@ -96,7 +96,7 @@ pub struct BotCommand {
impl BotCommand impl BotCommand
{ {
pub async fn execute(&self,m:botinstance::Chat,n:PrivmsgMessage){ pub async fn execute(&self,m:botinstance::BotManagers,n:PrivmsgMessage){
(self.exec_body)(m,n).await; (self.exec_body)(m,n).await;
} }
} }
@ -105,7 +105,7 @@ impl BotCommand
impl BotActionTrait for BotCommand impl BotActionTrait for BotCommand
{ {
fn add_to_bot(self, mut bot:BotInstance) { fn add_to_bot(self, mut bot:BotInstance) {
let mgr = &mut bot.botmgrs.botmodules; let mgr = &mut bot.botmodules;
self.add_to_modmgr(mgr); self.add_to_modmgr(mgr);
} }
@ -125,14 +125,16 @@ pub mod bot_actions {
use std::boxed::Box; use std::boxed::Box;
use std::pin::Pin; use std::pin::Pin;
use crate::core::botinstance::Chat; use crate::core::botinstance::{BotManagers, Chat};
use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::PrivmsgMessage;
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 type ExecBody<F> = Box<dyn Fn(Chat,PrivmsgMessage) -> Pin<Box<dyn Future<Output=F> + 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(BotManagers,PrivmsgMessage) -> Pin<Box<dyn Future<Output=()> + Send>> + Send + Sync>;
//pub fn asyncbox<T,F>(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody<F> //pub fn asyncbox<T,F>(f: fn(Chat,PrivmsgMessage) -> T) -> ExecBody<F>
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(BotManagers,PrivmsgMessage) -> T) -> ExecBody
where where
T: Future<Output=()> + Send + 'static, T: Future<Output=()> + Send + 'static,
{ {
@ -155,7 +157,7 @@ pub struct Listener
impl Listener impl Listener
{ {
pub async fn execute(&self,m:botinstance::Chat,n:PrivmsgMessage){ pub async fn execute(&self,m:botinstance::BotManagers,n:PrivmsgMessage){
(self.exec_body)(m,n).await; (self.exec_body)(m,n).await;
} }
} }
@ -164,7 +166,7 @@ impl BotActionTrait for Listener
{ {
fn add_to_bot(self, mut bot:BotInstance) { fn add_to_bot(self, mut bot:BotInstance) {
let mgr = &mut bot.botmgrs.botmodules; let mgr = &mut bot.botmodules;
self.add_to_modmgr(mgr); self.add_to_modmgr(mgr);
} }

View file

@ -32,7 +32,7 @@ pub fn init(mgr:&mut ModulesManager)
], ],
}.add_to_modmgr(mgr); }.add_to_modmgr(mgr);
async fn cmd_promote(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) { async fn cmd_promote(mut _chat:botinstance::BotManagers,_msg:PrivmsgMessage) {
//println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); //println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
println!("Called cmd promote"); println!("Called cmd promote");
@ -72,7 +72,7 @@ pub fn init(mgr:&mut ModulesManager)
}.add_to_modmgr(mgr); }.add_to_modmgr(mgr);
async fn cmd_demote(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) { async fn cmd_demote(mut _chat:botinstance::BotManagers,_msg:PrivmsgMessage) {
println!("Called cmd demote"); println!("Called cmd demote");
} }
@ -101,7 +101,7 @@ pub enum Permissible {
Block Block
} }
//#[derive(Clone)] #[derive(Clone)]
pub struct IdentityManager { pub struct IdentityManager {
special_roles_users : HashMap<String,Vec<UserRole>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel special_roles_users : HashMap<String,Vec<UserRole>>, // # <-- (!) This must be String instead of ChType because we're checking a User not a Channel
// parent_mgr : Box<crate::core::botinstance::BotManagers>, // parent_mgr : Box<crate::core::botinstance::BotManagers>,
@ -131,7 +131,7 @@ impl IdentityManager {
// [ ] Maybe I should create a can_user_run version that simply takes PrvMsg, but then calls can_user_run directly // [ ] Maybe I should create a can_user_run version that simply takes PrvMsg, but then calls can_user_run directly
// pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Result<Permissible,Box<dyn Error>> // pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Result<Permissible,Box<dyn Error>>
pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> &Permissible pub fn can_user_run_PRVMSG(self,msg:&PrivmsgMessage,cmdreqroles:Vec<UserRole>) -> Permissible
{ {
// println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text); // println!("(#{}) {}: {}", msg.channel_login, msg.sender.name, msg.message_text);
@ -152,7 +152,11 @@ impl IdentityManager {
// } // }
if let Some(sender_badge) = sender_badge { if let Some(sender_badge) = sender_badge {
return &self.can_user_run(msg.sender.name.to_owned(), // return &self.can_user_run(msg.sender.name.to_owned(),
// ChType::Channel(msg.channel_login.to_owned()),
// sender_badge,
// cmdreqroles
return self.can_user_run(msg.sender.name.to_owned(),
ChType::Channel(msg.channel_login.to_owned()), ChType::Channel(msg.channel_login.to_owned()),
sender_badge, sender_badge,
cmdreqroles cmdreqroles
@ -162,7 +166,7 @@ impl IdentityManager {
// [ ] Call can_user_run() // [ ] Call can_user_run()
&Permissible::Block Permissible::Block
} }
pub fn can_user_run(mut self, pub fn can_user_run(mut self,

View file

@ -69,7 +69,7 @@ pub fn init(mgr:&mut ModulesManager)
} }
async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage) async fn good_girl(mut bot:botinstance::BotManagers,msg:PrivmsgMessage)
{ {
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);
@ -88,9 +88,11 @@ async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage)
{ {
// chat.say_in_reply_to(&msg,String::from("GoodGirl")).await; // chat.say_in_reply_to(&msg,String::from("GoodGirl")).await;
//if rng.gen_ratio(1,5) { //if rng.gen_ratio(1,5) {
let rollwin = rand::thread_rng().gen_ratio(1,10); println!("In GoodGirl() > Pausechamp");
let rollwin = rand::thread_rng().gen_ratio(1,5);
if rollwin { if rollwin {
chat.say_in_reply_to(&msg,String::from("GoodGirl xdd ")).await; println!("In GoodGirl() > Win");
bot.chat.say_in_reply_to(&msg,String::from("GoodGirl xdd ")).await;
} }
} }
@ -100,7 +102,7 @@ async fn good_girl(mut chat:botinstance::Chat,msg:PrivmsgMessage)
} }
async fn testy(mut _chat:botinstance::Chat,_msg:PrivmsgMessage) async fn testy(mut _chat:botinstance::BotManagers,_msg:PrivmsgMessage)
{ {
println!("testy triggered!") println!("testy triggered!")