diff --git a/readme.md b/readme.md index bbd2096..3477c61 100644 --- a/readme.md +++ b/readme.md @@ -172,10 +172,13 @@ pub async fn main() { Result::Err("Not Valid message type".to_string()) } - /* 3. Set and Store the execution body using `async_box()` */ - cmd.set_exec_fn(asyncfn_box(execbody)); + /* 4. optionally, remove admin only default flag */ + cmd.set_admin_only(false); - /* 4. Load the cmd into the bot */ + /* 5. optionally, set min badge*/ + cmd.set_min_badge("broadcaster".to_string()); + + /* 6. Load the cmd into the bot */ bot.load_command(cmd); /* Run the bot */ diff --git a/src/bin/bot_cmd_example.rs b/src/bin/bot_cmd_example.rs index fa3d6a6..7335461 100644 --- a/src/bin/bot_cmd_example.rs +++ b/src/bin/bot_cmd_example.rs @@ -42,7 +42,13 @@ pub async fn main() { /* 3. Set and Store the execution body using `async_box()` */ cmd.set_exec_fn(asyncfn_box(execbody)); - /* 4. Load the cmd into the bot */ + /* 4. optionally, remove admin only default flag */ + cmd.set_admin_only(false); + + /* 5. optionally, set min badge*/ + cmd.set_min_badge("broadcaster".to_string()); + + /* 6. Load the cmd into the bot */ bot.load_command(cmd); /* Run the bot */ diff --git a/src/bin/fun_bot.rs b/src/bin/fun_bot.rs index 8469bee..7df3f4d 100644 --- a/src/bin/fun_bot.rs +++ b/src/bin/fun_bot.rs @@ -40,6 +40,9 @@ pub async fn main() { /* 3. Set and Store the execution body using `async_box()` */ cmd.set_exec_fn(asyncfn_box(execbody)); + cmd.set_admin_only(false); + cmd.set_min_badge("broadcaster".to_string()); + /* 4. Load the cmd into the bot */ bot.load_command(cmd); diff --git a/src/botcore/bot_objects/command.rs b/src/botcore/bot_objects/command.rs index 2239991..59df04b 100644 --- a/src/botcore/bot_objects/command.rs +++ b/src/botcore/bot_objects/command.rs @@ -92,6 +92,7 @@ impl Command if let ServerMessage::Privmsg(msg) = message { // dbg!(msg.clone()) + // dbg!(cmd.min_badge.clone()); for badge in msg.badges { match cmd.min_badge.as_str() { @@ -131,7 +132,7 @@ impl Command fn admin_only_ok(cmd:&Command,bot:Arc<Bot>,message:ServerMessage) -> bool { if let ServerMessage::Privmsg(msg) = message { - if cmd.admin_only && bot.get_admins().contains(&msg.sender.login) { + if (cmd.admin_only && bot.get_admins().contains(&msg.sender.login)) || !cmd.admin_only { return true; } else { return false; @@ -143,6 +144,14 @@ impl Command (cmd.custom_cond_fn)(bot,message) } + // dbg!(msg.clone()); + + // dbg!(caller_badge_ok(self, bot.clone(), msg.clone())); + // dbg!(cmd_called(self, bot.clone(), msg.clone()) && + // caller_badge_ok(self, bot.clone(), msg.clone()) && + // admin_only_ok(self, bot.clone(), msg.clone()) && + // custom_cond_ok(self, bot.clone(), msg.clone())); + cmd_called(self, bot.clone(), msg.clone()) && caller_badge_ok(self, bot.clone(), msg.clone()) && admin_only_ok(self, bot.clone(), msg.clone()) && @@ -154,4 +163,15 @@ impl Command pub async fn execute_fn(&self,bot:Arc<Bot>,msg:ServerMessage) -> Result<String, String> { (self.exec_fn)(bot,msg).await } + + + /// sets min_badge to run the cmd + pub fn set_min_badge(&mut self,min_badge:String) { + self.min_badge = min_badge + } + + /// sets admin_only + pub fn set_admin_only(&mut self,admin_only:bool) { + self.admin_only = admin_only + } } diff --git a/src/lib.rs b/src/lib.rs index 4b1a70d..9c0379d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,13 @@ //! /* 3. Set and Store the execution body using `async_box()` */ //! cmd.set_exec_fn(asyncfn_box(execbody)); //! -//! /* 4. Load the cmd into the bot */ +//! /* 4. optionally, remove admin only default flag */ +//! cmd.set_admin_only(false); +//! +//! /* 5. optionally, set min badge*/ +//! cmd.set_min_badge("broadcaster".to_string()); +//! +//! /* 6. Load the cmd into the bot */ //! bot.load_command(cmd); //! //! /* Run the bot */