From 29c8f745319ffae0a8959861aaeda82aa5dcd7b4 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:16:41 -0400 Subject: [PATCH] (cont) disable cmd logic --- src/core/botmodules.rs | 123 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index a199481..df0595f 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -223,6 +223,7 @@ pub async fn init(mgr: Arc) { .say_in_reply_to(&msg, outmsg.to_string()) .await; + } @@ -281,6 +282,128 @@ pub async fn init(mgr: Arc) { 3c. , and is -f (forced) , return a Success */ + + // [x] Unwraps arguments from message + + let (arg1, arg2) = { + + let mut argv = msg.message_text.split(' '); + + argv.next(); // Skip the command name + + let arg1 = argv.next(); + + let arg2 = argv.next(); + + (arg1, arg2) + }; + + + /* -- Related function to call later + exec_disable( + &self, + requestor: String, + requestor_badge: Option, + trg_module: ModType, + // channel: Option, + trg_level: StatusLvl, + force: bool, + // bot: BotAR, + id: Arc>, + ) -> ChangeResult + */ + + + // [x] requestor: String, + let requestor = msg.clone().sender.name; + + + // [x] requestor_badge: Option, + + let mut requestor_badge_mut: Option = None; + + for b in &msg.badges { + if b.name == "moderator" { + requestor_badge_mut = Some(ChatBadge::Mod); + } else if b.name == "broadcaster" { + requestor_badge_mut = Some(ChatBadge::Broadcaster); + } + } + + let requestor_badge = requestor_badge_mut; + + // [x] trg_module: ModType, + // - [x] Need to validate an actual ModType - otherwise, fail or exit the cmd + + let trg_module = if (arg1 == Some("-i")) || (arg1 == Some("-f")) { arg2 } else { arg1 }; + + // if no trg_module was passed + if let None = trg_module { + + let botlock = bot.read().await; + + let outmsg = "uuh You need to pass a module"; + + botlog::debug( + outmsg, + Some("botmodules.rs > cmd_disable()".to_string()), + Some(&msg), + ); + + botlock + .botmgrs + .chat + .say_in_reply_to(&msg, outmsg.to_string()) + .await; + + return; + + } + + + + // [x] trg_level: StatusLvl, + + let currchnl = msg.channel_login.to_lowercase(); + + let trg_level = + if arg1 == Some("-i") { StatusLvl::Instance } + else if arg1 == Some("-f") { StatusLvl::Instance } + else { StatusLvl::Ch(ChType::Channel(currchnl)) } + ; + + + + let botlock = bot.read().await; + let modmgr = Arc::clone(&botlock.botmodules); + let id = botlock.get_identity(); + + let force = arg1 == Some("-f"); + + // modmgr.exec_enable(requestor, requestor_badge, trg_module, trg_level, id) + let rslt = modmgr.exec_disable( + requestor, + requestor_badge, + ModType::BotModule(trg_module.unwrap().to_string()), + trg_level, + force, + id).await; + + + let outmsg = match rslt.clone() { + ChangeResult::Failed(a) => format!("Stare Failed : {}",a), + ChangeResult::NoChange(a) => format!("Hmm No Change : {}",a), + ChangeResult::Success(a) => format!("YAAY Success : {}",a), + }; + + botlock + .botmgrs + .chat + .say_in_reply_to(&msg, outmsg.to_string()) + .await; + + + }