diff options
| author | Illia K <[email protected]> | 2016-11-28 19:21:33 +0000 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-28 12:13:46 -0800 |
| commit | 83515e1a5ccc850a8c352060a19394a53aed8454 (patch) | |
| tree | e5531327c82e37ae8b6874ebcba4b81746b4dd1e /src/ext/framework/command.rs | |
| parent | Improve docs and add new message builder methods (diff) | |
| download | serenity-83515e1a5ccc850a8c352060a19394a53aed8454.tar.xz serenity-83515e1a5ccc850a8c352060a19394a53aed8454.zip | |
Add before/after framework command hooks
These hooks will each be run prior to or after the command, and will
finish execution before executing the command.
These can be configured in a Framework via:
```rs
client.with_framework(|f| f
.before(|_context, message, _command_name| {
println!("Got command '{}'", command_name);
})
.after(|_context, _message, command_name| {
println!("Finished command '{}'", command_name);
}));
```
This does introduce a backwards compatibility break, by requiring
commands' Context/Message to be borrowed
Upgrade path:
If not using the `command!` macro, modify command signatures from:
```rs
fn some_command(context: Context, message: Message, args: Vec<String>)
```
to
```rs
fn some_command(context: &Context, message: &Message, args: Vec<String>)
```
Diffstat (limited to 'src/ext/framework/command.rs')
| -rw-r--r-- | src/ext/framework/command.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/ext/framework/command.rs b/src/ext/framework/command.rs index 0c595b3..e0a4616 100644 --- a/src/ext/framework/command.rs +++ b/src/ext/framework/command.rs @@ -4,7 +4,7 @@ use ::client::Context; use ::model::Message; #[doc(hidden)] -pub type Command = Fn(Context, Message, Vec<String>) + Send + Sync; +pub type Command = Fn(&Context, &Message, Vec<String>) + Send + Sync; #[doc(hidden)] pub type InternalCommand = Arc<Command>; |