(cont) enable cmd logic
This commit is contained in:
parent
8b4c21ba58
commit
7757dd1820
2 changed files with 49 additions and 29 deletions
|
@ -25,7 +25,7 @@ use crate::core::botlog;
|
|||
use crate::core::chat::Chat;
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum ChangeResult {
|
||||
Success(String),
|
||||
Failed(String),
|
||||
|
|
|
@ -108,7 +108,7 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
|
||||
|
||||
// [ ] Unwraps arguments from message
|
||||
// [x] Unwraps arguments from message
|
||||
|
||||
let (arg1, arg2) = {
|
||||
|
||||
|
@ -137,11 +137,11 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
*/
|
||||
|
||||
|
||||
// [ ] requestor: String,
|
||||
let requester = msg.clone().sender.name;
|
||||
// [x] requestor: String,
|
||||
let requestor = msg.clone().sender.name;
|
||||
|
||||
|
||||
// [ ] requestor_badge: Option<ChatBadge>,
|
||||
// [x] requestor_badge: Option<ChatBadge>,
|
||||
|
||||
let mut requestor_badge_mut: Option<ChatBadge> = None;
|
||||
|
||||
|
@ -156,41 +156,36 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
let requestor_badge = requestor_badge_mut;
|
||||
|
||||
|
||||
// [ ] trg_module: ModType,
|
||||
// - [ ] Need to validate an actual ModType - otherwise, fail or exit the cmd
|
||||
// [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 let Some(trg_module_str) = trg_module {
|
||||
// if no trg_module was passed
|
||||
if let None = trg_module {
|
||||
|
||||
let botlock = bot.read().await;
|
||||
let modmgr = Arc::clone(&botlock.botmodules);
|
||||
let modlist = modmgr.moduleslist().await;
|
||||
let rslt = modlist.get(&ModType::BotModule(trg_module_str.to_string()));
|
||||
|
||||
if let None = rslt {
|
||||
let outmsg = "uuh You need to pass a module";
|
||||
|
||||
let outmsg = "uuh module doesn't exist";
|
||||
botlog::debug(
|
||||
outmsg,
|
||||
Some("botmodules.rs > cmd_enable()".to_string()),
|
||||
Some(&msg),
|
||||
);
|
||||
|
||||
botlog::debug(
|
||||
outmsg,
|
||||
Some("botmodules.rs > cmd_enable()".to_string()),
|
||||
Some(&msg),
|
||||
);
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, outmsg.to_string())
|
||||
.await;
|
||||
|
||||
botlock
|
||||
.botmgrs
|
||||
.chat
|
||||
.say_in_reply_to(&msg, outmsg.to_string())
|
||||
.await;
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// [ ] trg_level: StatusLvl,
|
||||
// [x] trg_level: StatusLvl,
|
||||
|
||||
let currchnl = msg.channel_login.to_lowercase();
|
||||
|
||||
|
@ -202,6 +197,31 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
|||
|
||||
|
||||
|
||||
let botlock = bot.read().await;
|
||||
let modmgr = Arc::clone(&botlock.botmodules);
|
||||
let id = botlock.get_identity();
|
||||
|
||||
|
||||
// modmgr.exec_enable(requestor, requestor_badge, trg_module, trg_level, id)
|
||||
let rslt = modmgr.exec_enable(
|
||||
requestor,
|
||||
requestor_badge,
|
||||
ModType::BotModule(trg_module.unwrap().to_string()),
|
||||
trg_level,
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue