diff --git a/src/core/chat.rs b/src/core/chat.rs index 5ca8a61..7f00a7e 100644 --- a/src/core/chat.rs +++ b/src/core/chat.rs @@ -79,9 +79,15 @@ impl Chat { let rl = Arc::clone(&self.ratelimiters); let mut rllock = rl.lock().await; + botlog::debug( + &format!("Ratelimiter being checked for channel : {}",channel_login.clone()), + Some("Chat > send_botmsg".to_string()), + None, + ); + let contextratelimiter = rllock // .get_mut() - .get_mut(&Channel(String::from(channel_login.clone()))) + .get_mut(&Channel(String::from(channel_login.to_lowercase().clone()))) .expect("ERROR: Issue with Rate limiters"); // Continue to check the limiter and sleep if required if the minimum is not reached @@ -154,10 +160,9 @@ impl Chat { } - async fn _say(&self, channel_login: String, message: String) { + pub async fn say(&self, channel_login: String, message: String) { // more info https://docs.rs/twitch-irc/latest/twitch_irc/client/struct.TwitchIRCClient.html#method.say - // self.client.say(msg,outmsg).await.unwrap(); self.send_botmsg(BotMsgType::Say(channel_login, message)).await; } diff --git a/src/custom.rs b/src/custom.rs index fc802e6..6107797 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -1,5 +1,5 @@ /* - `modules` will : + `custom` will : - be a starting refrence point for the bot instance to pull module definitions for */ @@ -11,7 +11,8 @@ pub use crate::core::botmodules::ModulesManager; // [ ] Load submodules -mod experiments; +// mod experiments; +mod experimental; // [ ] init() function that accepts bot instance - this is passed to init() on submodules @@ -19,5 +20,6 @@ pub async fn init(mgr: Arc) { // Modules initializer loads modules into the bot // this is achieved by calling submodules that also have fn init() defined - experiments::init(mgr).await + // experiments::init(mgr).await + experimental::init(mgr).await; } diff --git a/src/custom/experimental.rs b/src/custom/experimental.rs new file mode 100644 index 0000000..e2aa67e --- /dev/null +++ b/src/custom/experimental.rs @@ -0,0 +1,24 @@ +/* + `experimental` will : + - be for mostly experimental +*/ + +use std::sync::Arc; + +pub use crate::core::botinstance::BotInstance; +pub use crate::core::botmodules::ModulesManager; + +// [ ] Load submodules + +mod experiment001; +mod experiment002; + +// [ ] init() function that accepts bot instance - this is passed to init() on submodules + +pub async fn init(mgr: Arc) { + // Modules initializer loads modules into the bot + // this is achieved by calling submodules that also have fn init() defined + + experiment001::init(Arc::clone(&mgr)).await; + experiment002::init(Arc::clone(&mgr)).await; +} diff --git a/src/custom/experiments.rs b/src/custom/experimental/experiment001.rs similarity index 100% rename from src/custom/experiments.rs rename to src/custom/experimental/experiment001.rs diff --git a/src/custom/experimental/experiment002.rs b/src/custom/experimental/experiment002.rs new file mode 100644 index 0000000..d3b70e5 --- /dev/null +++ b/src/custom/experimental/experiment002.rs @@ -0,0 +1,135 @@ +/* + Custom Modules - + + Usage : + [ ] within the file's init(), define BotActions & Load them into the ModulesManager + [ ] Define Execution Bodies for these BotActions + [ ] Afterwards, add the following to parent modules.rs file + - mod ; + - within init(), ::init(mgr).await + +*/ + +// use rand::Rng; +use std::sync::Arc; + +use twitch_irc::message::PrivmsgMessage; + +// use crate::core::botinstance::ChType::Channel; +use crate::core::botinstance::ChType; +use ChType::Channel; +use crate::core::botlog; + +use casual_logger::Log; + +use crate::core::bot_actions::actions_util::{self, BotAR}; +use crate::core::botmodules::{BotActionTrait, BotCommand, BotModule, ModulesManager}; + +use crate::core::identity::UserRole::*; + +// use tokio::time::{sleep, Duration}; + +pub async fn init(mgr: Arc) { + + const OF_CMD_CHANNEL:ChType = Channel(String::new()); + + + // 1. Define the BotAction + let botc1 = BotCommand { + module: BotModule(String::from("experiments002")), + command: String::from("say"), // command call name + alias: vec![ + "s".to_string(), + ], // String of alternative names + exec_body: actions_util::asyncbox(sayout), + help: String::from("Test Command tester"), + required_roles: vec![ + BotAdmin, + Mod(OF_CMD_CHANNEL), + ], + }; + + // 2. Add the BotAction to ModulesManager + botc1.add_to_modmgr(Arc::clone(&mgr)).await; + + mgr.set_instance_enabled(BotModule(String::from("experiments002"))).await; + + +} + + +async fn sayout(bot: BotAR, msg: PrivmsgMessage) { + + /* + usage : + + */ + + // [x] Unwraps arguments from message + + let argrslt = + if let Some((_,str1)) = msg.message_text.split_once(" ") { + if let Some((channelstr,msgstr)) = str1.split_once(" ") { + // println!("{}",cmdstr); + // println!("{}",channelstr); + // println!("{}",msgstr); + Some((channelstr,msgstr)) + } + else { None } + } + else { None }; + + + + + match argrslt { + Some((trgchnl,outmsg)) => { + + let newoutmsg = format!("{} (from #{}) says : {}", + msg.sender.name,msg.channel_login, outmsg); + + + let bot = Arc::clone(&bot); + + let botlock = bot.read().await; + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say(trgchnl.to_string(), newoutmsg.to_string()) + .await; + + // botlog::debug( + // "Sayout had issues trying to parse arguments", + // Some("experiment002 > sayout".to_string()), + // Some(&msg), + // ); + + + }, + None => { + botlog::debug( + "sayout had issues trying to parse arguments", + Some("experiment002 > sayout".to_string()), + Some(&msg), + ); + + let bot = Arc::clone(&bot); + + let botlock = bot.read().await; + + // uses chat.say_in_reply_to() for the bot controls for messages + botlock + .botmgrs + .chat + .say_in_reply_to(&msg, String::from("Invalid arguments")) + .await; + + }, + + } + + + Log::flush(); +} \ No newline at end of file