cmd set admin only & min badge

This commit is contained in:
modulatingforce 2025-01-28 12:47:21 -05:00
parent 3e4584c39f
commit b2244a81eb
5 changed files with 44 additions and 6 deletions

View file

@ -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 */

View file

@ -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 */

View file

@ -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);

View file

@ -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
}
}

View file

@ -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 */