ModulesManager #37

Merged
modulatingforce merged 22 commits from modulesmanager into main 2024-03-22 21:34:08 -04:00
Showing only changes of commit 29c8f74531 - Show all commits

View file

@ -223,6 +223,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
.say_in_reply_to(&msg, outmsg.to_string())
.await;
}
@ -281,6 +282,128 @@ pub async fn init(mgr: Arc<ModulesManager>) {
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<ChatBadge>,
trg_module: ModType,
// channel: Option<ChType>,
trg_level: StatusLvl,
force: bool,
// bot: BotAR,
id: Arc<RwLock<IdentityManager>>,
) -> ChangeResult
*/
// [x] requestor: String,
let requestor = msg.clone().sender.name;
// [x] requestor_badge: Option<ChatBadge>,
let mut requestor_badge_mut: Option<ChatBadge> = 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;
}