multi command
This commit is contained in:
parent
0c9cd1b3ec
commit
2a884f9571
5 changed files with 74 additions and 11 deletions
src
|
@ -49,7 +49,7 @@ pub mod funbot_objs {
|
|||
/// Create a Command Object
|
||||
fn create_cmd_test() -> Command {
|
||||
|
||||
let mut cmd = Command::new("remind besty".to_string(),"annytfYandere ".to_string());
|
||||
let mut cmd = Command::new(vec!["remind besty".to_string()],"annytfYandere ".to_string());
|
||||
|
||||
async fn execbody(bot:Arc<Bot>,message:ServerMessage) -> Result<String,String> {
|
||||
if let ServerMessage::Privmsg(msg) = message {
|
||||
|
|
|
@ -29,7 +29,7 @@ pub async fn main() {
|
|||
let mut bot = Bot::new();
|
||||
|
||||
/* 1. Create a new blank cmd */
|
||||
let mut cmd = Command::new("test".to_string(),"".to_string());
|
||||
let mut cmd = Command::new(vec!["test".to_string()],"".to_string());
|
||||
|
||||
/* 2. Define an async fn callback execution */
|
||||
async fn execbody(bot:Arc<Bot>,message:ServerMessage) -> Result<String,String> {
|
||||
|
|
|
@ -55,7 +55,7 @@ pub mod custom_mod {
|
|||
|
||||
pub fn cmd_test() -> Command {
|
||||
/* 1. Create a new cmd */
|
||||
let mut cmd = Command::new("test".to_string(),"".to_string());
|
||||
let mut cmd = Command::new(vec!["test".to_string()],"".to_string());
|
||||
|
||||
/* 2. Define exec callback */
|
||||
async fn execbody(bot:Arc<Bot>,message:ServerMessage) -> Result<String,String> {
|
||||
|
|
|
@ -59,7 +59,7 @@ pub mod built_in_objects {
|
|||
|
||||
fn create_disable_cmd() -> Command {
|
||||
/* 1. Create a new blank cmd */
|
||||
let mut cmd = Command::new("disable".to_string(),"".to_string());
|
||||
let mut cmd = Command::new(vec!["disable".to_string()],"".to_string());
|
||||
|
||||
/* 2. Define an async fn callback execution */
|
||||
async fn execbody(bot:Arc<Bot>,message:ServerMessage) -> Result<String,String> {
|
||||
|
@ -88,7 +88,7 @@ pub mod built_in_objects {
|
|||
|
||||
fn create_enable_cmd() -> Command {
|
||||
/* 1. Create a new blank cmd */
|
||||
let mut cmd = Command::new("enable".to_string(),"".to_string());
|
||||
let mut cmd = Command::new(vec!["enable".to_string()],"".to_string());
|
||||
|
||||
/* 2. Define an async fn callback execution */
|
||||
async fn execbody(bot:Arc<Bot>,message:ServerMessage) -> Result<String,String> {
|
||||
|
@ -116,4 +116,51 @@ pub mod built_in_objects {
|
|||
}
|
||||
|
||||
|
||||
/// adminonly command that grants a temporary role
|
||||
fn create_iam_role_cmd() -> Command {
|
||||
/* 1. Create a new blank cmd */
|
||||
let mut cmd = Command::new(vec![
|
||||
"I am ".to_string(),
|
||||
"I'm ".to_string()
|
||||
],"".to_string());
|
||||
|
||||
/* 2. Define an async fn callback execution */
|
||||
async fn execbody(bot:Arc<Bot>,message:ServerMessage) -> Result<String,String> {
|
||||
if let ServerMessage::Privmsg(msg) = message {
|
||||
for (i,arg) in msg.message_text.split(" ").enumerate() {
|
||||
if i > 1 {
|
||||
// bot.disable_module(msg.channel_login.clone(), arg.to_string()).await;
|
||||
// #todo
|
||||
// if not dont have the badge or have a lower priviledge badge
|
||||
// and they dont have an active guest badge, ths admin can be
|
||||
// recognzed wth that badge
|
||||
if arg == "mod" || arg == "moderator" {
|
||||
|
||||
}
|
||||
if arg == "vip" {
|
||||
|
||||
}
|
||||
if arg == "broadcaster" || arg == "strimmer" || arg == "streamer" {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = bot.client.say_in_reply_to(&msg, String::from("Disabled!")).await ;
|
||||
}
|
||||
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(true);
|
||||
|
||||
// /* 5. optionally, set min badge*/
|
||||
// cmd.set_min_badge(Badge::Moderator);
|
||||
cmd
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@ use super::ExecBody;
|
|||
#[derive(Clone)]
|
||||
pub struct Command
|
||||
{
|
||||
command : String,
|
||||
commands : Vec<String>,
|
||||
exec_fn : Arc<ExecBody>,
|
||||
min_badge : Badge,
|
||||
admin_only : bool,
|
||||
|
@ -38,13 +38,13 @@ impl Command
|
|||
/// if a blank prefix is given, the bot will look for the bot prefix instead
|
||||
///
|
||||
/// By default, the new command is admin_only
|
||||
pub fn new(command:String,prefix:String) -> Command {
|
||||
pub fn new(commands:Vec<String>,prefix:String) -> Command {
|
||||
|
||||
async fn execbody(_:Arc<Bot>,_:ServerMessage) -> Result<String,String>
|
||||
{ Result::Ok("success".to_string()) }
|
||||
|
||||
Command {
|
||||
command ,
|
||||
commands ,
|
||||
prefix ,
|
||||
exec_fn : Arc::new(asyncfn_box(execbody)),
|
||||
min_badge : Badge::Vip,
|
||||
|
@ -79,12 +79,28 @@ impl Command
|
|||
} else {
|
||||
prefixed_cmd.push_str(&cmd.prefix);
|
||||
}
|
||||
prefixed_cmd.push_str(&cmd.command);
|
||||
return message.message_text.starts_with(prefixed_cmd.as_str())
|
||||
for cmd_nm in &cmd.commands {
|
||||
prefixed_cmd.push_str(cmd_nm);
|
||||
if message.message_text.starts_with(prefixed_cmd.as_str()) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
fn caller_badge_ok(cmd:&Command,_bot:Arc<Bot>,message:PrivmsgMessage) -> bool {
|
||||
fn caller_badge_ok(cmd:&Command,bot:Arc<Bot>,message:PrivmsgMessage) -> bool {
|
||||
|
||||
// senders that are admins skip badge check if the command is adminonly
|
||||
if cmd.admin_only && bot.get_admins().contains(&message.sender.login) {
|
||||
return true;
|
||||
} ;
|
||||
|
||||
// adminonly commands will can only be ran by admins
|
||||
if cmd.admin_only && bot.get_admins().contains(&message.sender.login) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for badge in message.badges {
|
||||
|
||||
match cmd.min_badge {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue