From bcdd4f125d029c6d4c8a3ca79ba3ebecdb9515ab Mon Sep 17 00:00:00 2001 From: Austin Hellyer Date: Mon, 7 Nov 2016 13:52:50 -0800 Subject: Add arguments to framework commands --- src/ext/framework/command.rs | 2 +- src/ext/framework/mod.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/ext/framework') diff --git a/src/ext/framework/command.rs b/src/ext/framework/command.rs index 31b2520..43d3c9a 100644 --- a/src/ext/framework/command.rs +++ b/src/ext/framework/command.rs @@ -2,6 +2,6 @@ use std::sync::Arc; use ::client::Context; use ::model::Message; -pub type Command = Fn(Context, Message) + Send + Sync; +pub type Command = Fn(Context, Message, Vec) + Send + Sync; #[doc(hidden)] pub type InternalCommand = Arc; diff --git a/src/ext/framework/mod.rs b/src/ext/framework/mod.rs index c504d53..1949e24 100644 --- a/src/ext/framework/mod.rs +++ b/src/ext/framework/mod.rs @@ -113,7 +113,12 @@ impl Framework { let command = command.clone(); thread::spawn(move || { - (command)(context, message) + let args = message.content[built.len() + 1..] + .split_whitespace() + .map(|arg| arg.to_owned()) + .collect::>(); + + (command)(context, message, args) }); return; @@ -123,7 +128,7 @@ impl Framework { } pub fn on(mut self, command_name: S, f: F) -> Self - where F: Fn(Context, Message) + Send + Sync + 'static, + where F: Fn(Context, Message, Vec) + Send + Sync + 'static, S: Into { self.commands.insert(command_name.into(), Arc::new(f)); self.initialized = true; -- cgit v1.2.3