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/mod.rs | |
| 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/mod.rs')
| -rw-r--r-- | src/framework/mod.rs | 28 |
1 files changed, 18 insertions, 10 deletions
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) }, |