diff options
| author | acdenisSK <[email protected]> | 2017-08-18 00:53:20 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-08-18 00:53:20 +0200 |
| commit | 106a4d5f8ff22a829a9486ce88fa8326184828fa (patch) | |
| tree | 650c539ce1fac58f07f568077a6c396b54cc9027 /src/framework | |
| parent | Fix args when `use_quotes` is true (diff) | |
| download | serenity-106a4d5f8ff22a829a9486ce88fa8326184828fa.tar.xz serenity-106a4d5f8ff22a829a9486ce88fa8326184828fa.zip | |
Allow the user to be given the original message (as in, the message used to construct the `args`)
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/command.rs | 4 | ||||
| -rw-r--r-- | src/framework/create_command.rs | 4 | ||||
| -rw-r--r-- | src/framework/create_group.rs | 2 | ||||
| -rw-r--r-- | src/framework/mod.rs | 28 |
4 files changed, 23 insertions, 15 deletions
diff --git a/src/framework/command.rs b/src/framework/command.rs index 74afb0d..ed38a14 100644 --- a/src/framework/command.rs +++ b/src/framework/command.rs @@ -5,7 +5,7 @@ use model::{Message, Permissions}; use std::collections::HashMap; 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 Exec = Fn(&mut Context, &Message, Vec<String>, String) -> Result<(), String> + 'static; pub type Help = Fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, &[String]) -> Result<(), String> + 'static; @@ -69,7 +69,7 @@ pub struct Command { impl Command { pub fn new<F>(f: F) -> Self - where F: Fn(&mut Context, &Message, Vec<String>) -> Result<(), String> + 'static { + where F: Fn(&mut Context, &Message, Vec<String>, String) -> Result<(), String> + 'static { Command { aliases: Vec::new(), checks: Vec::default(), diff --git a/src/framework/create_command.rs b/src/framework/create_command.rs index cf78174..3bb019c 100644 --- a/src/framework/create_command.rs +++ b/src/framework/create_command.rs @@ -97,7 +97,7 @@ impl CreateCommand { /// /// [`exec_str`]: #method.exec_str pub fn exec<F>(mut self, func: F) -> Self - where F: Fn(&mut Context, &Message, Vec<String>) -> Result<(), String> + where F: Fn(&mut Context, &Message, Vec<String>, String) -> Result<(), String> + Send + Sync + 'static { @@ -217,7 +217,7 @@ impl Default for Command { Command { aliases: Vec::new(), checks: Vec::default(), - exec: CommandType::Basic(Box::new(|_, _, _| Ok(()))), + exec: CommandType::Basic(Box::new(|_, _, _, _| Ok(()))), desc: None, usage: None, example: None, diff --git a/src/framework/create_group.rs b/src/framework/create_group.rs index 74d8a82..a999268 100644 --- a/src/framework/create_group.rs +++ b/src/framework/create_group.rs @@ -55,7 +55,7 @@ impl CreateGroup { /// Adds a command to group with simplified API. /// You can return Err(string) if there's an error. pub fn on<F>(mut self, command_name: &str, f: F) -> Self - where F: Fn(&mut Context, &Message, Vec<String>) -> Result<(), String> + where F: Fn(&mut Context, &Message, Vec<String>, String) -> Result<(), String> + Send + Sync + 'static { diff --git a/src/framework/mod.rs b/src/framework/mod.rs index 8a621b2..03ee742 100644 --- a/src/framework/mod.rs +++ b/src/framework/mod.rs @@ -122,7 +122,7 @@ use model::Channel; macro_rules! command { ($fname:ident($c:ident) $b:block) => { #[allow(unreachable_code, unused_mut)] - pub fn $fname(mut $c: &mut $crate::client::Context, _: &$crate::model::Message, _: Vec<String>) -> ::std::result::Result<(), String> { + pub fn $fname(mut $c: &mut $crate::client::Context, _: &$crate::model::Message, _: Vec<String>, _: String) -> ::std::result::Result<(), String> { $b Ok(()) @@ -130,7 +130,7 @@ macro_rules! command { }; ($fname:ident($c:ident, $m:ident) $b:block) => { #[allow(unreachable_code, unused_mut)] - pub fn $fname(mut $c: &mut $crate::client::Context, $m: &$crate::model::Message, _: Vec<String>) -> ::std::result::Result<(), String> { + pub fn $fname(mut $c: &mut $crate::client::Context, $m: &$crate::model::Message, _: Vec<String>, _: String) -> ::std::result::Result<(), String> { $b Ok(()) @@ -138,7 +138,15 @@ macro_rules! command { }; ($fname:ident($c:ident, $m:ident, $a:ident) $b:block) => { #[allow(unreachable_code, unused_mut)] - pub fn $fname(mut $c: &mut $crate::client::Context, $m: &$crate::model::Message, $a: Vec<String>) -> ::std::result::Result<(), String> { + pub fn $fname(mut $c: &mut $crate::client::Context, $m: &$crate::model::Message, $a: Vec<String>, _: String) -> ::std::result::Result<(), String> { + $b + + Ok(()) + } + }; + ($fname:ident($c:ident, $m:ident, @$a:ident) $b:block) => { + #[allow(unreachable_code, unused_mut)] + pub fn $fname(mut $c: &mut $crate::client::Context, $m: &$crate::model::Message, _: Vec<String>, $a: String) -> ::std::result::Result<(), String> { $b Ok(()) @@ -146,7 +154,7 @@ macro_rules! command { }; ($fname:ident($c:ident, $m:ident, $a:ident, $($name:ident: $t:ty),*) $b:block) => { #[allow(unreachable_code, unreachable_patterns, unused_mut)] - pub fn $fname(mut $c: &mut $crate::client::Context, $m: &$crate::model::Message, $a: Vec<String>) -> ::std::result::Result<(), String> { + pub fn $fname(mut $c: &mut $crate::client::Context, $m: &$crate::model::Message, $a: Vec<String>, _: String) -> ::std::result::Result<(), String> { let mut i = $a.iter(); let mut arg_counter = 0; @@ -642,7 +650,7 @@ impl BuiltinFramework { /// # } /// ``` pub fn on<F, S>(mut self, command_name: S, f: F) -> Self - where F: Fn(&mut Context, &Message, Vec<String>) -> Result<(), String> + 'static, + where F: Fn(&mut Context, &Message, Vec<String>, String) -> Result<(), String> + 'static, S: Into<String> { { let ungrouped = self.groups @@ -935,12 +943,12 @@ impl ::Framework for BuiltinFramework { let after = self.after.clone(); let groups = self.groups.clone(); - let args = { + let (args, content) = { let mut content = message.content[position..].trim(); content = content[command_length..].trim(); if command.use_quotes { - utils::parse_quotes(content) + (utils::parse_quotes(content), content.to_string()) } else { let delimiters = &self.configuration.delimiters; let regular_expression = delimiters.iter() @@ -948,9 +956,9 @@ impl ::Framework for BuiltinFramework { let regex = Regex::new(®ular_expression).unwrap(); - regex.split(content) + (regex.split(content) .filter_map(|p| if !p.is_empty() { Some(p.to_string()) } else { None }) - .collect::<Vec<_>>() + .collect::<Vec<_>>(), content.to_string()) } }; @@ -981,7 +989,7 @@ impl ::Framework for BuiltinFramework { Ok(()) }, - CommandType::Basic(ref x) => (x)(&mut context, &message, args), + CommandType::Basic(ref x) => (x)(&mut context, &message, args, content), CommandType::WithCommands(ref x) => { (x)(&mut context, &message, groups, &args) }, |