diff options
| author | acdenisSK <[email protected]> | 2017-08-16 22:24:43 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-08-16 22:25:30 +0200 |
| commit | 005437f56869e846ff677b6516605def0c4de7bc (patch) | |
| tree | 8059c36c4564cafcd6effe086daa4c7ebe6d0218 /src/framework | |
| parent | a little for-loop to iterator change (diff) | |
| download | serenity-005437f56869e846ff677b6516605def0c4de7bc.tar.xz serenity-005437f56869e846ff677b6516605def0c4de7bc.zip | |
Provide the args to the checks
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/command.rs | 2 | ||||
| -rw-r--r-- | src/framework/create_command.rs | 4 | ||||
| -rw-r--r-- | src/framework/mod.rs | 16 |
3 files changed, 12 insertions, 10 deletions
diff --git a/src/framework/command.rs b/src/framework/command.rs index 7a44bc4..74afb0d 100644 --- a/src/framework/command.rs +++ b/src/framework/command.rs @@ -4,7 +4,7 @@ use client::Context; use model::{Message, Permissions}; use std::collections::HashMap; -pub type Check = Fn(&mut Context, &Message, &Arc<Command>) -> bool + 'static; +pub type Check = Fn(&mut Context, &Message, &[String], &Arc<Command>) -> bool + 'static; pub type Exec = Fn(&mut Context, &Message, Vec<String>) -> Result<(), String> + 'static; pub type Help = Fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, &[String]) -> Result<(), String> diff --git a/src/framework/create_command.rs b/src/framework/create_command.rs index 495fdd6..cf78174 100644 --- a/src/framework/create_command.rs +++ b/src/framework/create_command.rs @@ -57,13 +57,13 @@ impl CreateCommand { /// Ok(()) /// } /// - /// fn owner_check(_context: &mut Context, message: &Message, _: &Arc<Command>) -> bool { + /// fn owner_check(_context: &mut Context, message: &Message, _: &[String], _: &Arc<Command>) -> bool { /// // replace with your user ID /// message.author.id == 7 /// } /// ``` pub fn check<F>(mut self, check: F) -> Self - where F: Fn(&mut Context, &Message, &Arc<Command>) -> bool + Send + Sync + 'static { + where F: Fn(&mut Context, &Message, &[String], &Arc<Command>) -> bool + Send + Sync + 'static { self.0.checks.push(Box::new(check)); self diff --git a/src/framework/mod.rs b/src/framework/mod.rs index 69b0de8..c5cfb90 100644 --- a/src/framework/mod.rs +++ b/src/framework/mod.rs @@ -505,7 +505,7 @@ impl BuiltinFramework { mut context: &mut Context, message: &Message, command: &Arc<Command>, - args: usize, + args: &[String], to_check: &str, built: &str) -> Option<DispatchError> { @@ -539,20 +539,22 @@ impl BuiltinFramework { } } + let arg_len = args.len(); + if let Some(x) = command.min_args { - if args < x as usize { + if arg_len < x as usize { return Some(DispatchError::NotEnoughArguments { min: x, - given: args, + given: arg_len, }); } } if let Some(x) = command.max_args { - if args > x as usize { + if arg_len > x as usize { return Some(DispatchError::TooManyArguments { max: x, - given: args, + given: arg_len, }); } } @@ -584,7 +586,7 @@ impl BuiltinFramework { } else if !command .checks .iter() - .all(|check| (check)(&mut context, message, command)) { + .all(|check| (check)(&mut context, message, args, command)) { Some(DispatchError::CheckFailed) } else if self.configuration .blocked_users @@ -956,7 +958,7 @@ impl ::Framework for BuiltinFramework { &mut context, &message, &command, - args.len(), + &args, &to_check, &built, ) { |