aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-26 10:40:20 -0800
committerAustin Hellyer <[email protected]>2016-11-26 10:40:20 -0800
commit5edb49f94ae6c26fa92cebe178c8e3ea59979ed2 (patch)
treeb06b3648b6753cd1ceccd9441dcb3c61487c08cf /src
parentAdd Cache::get_guild_channel (diff)
downloadserenity-5edb49f94ae6c26fa92cebe178c8e3ea59979ed2.tar.xz
serenity-5edb49f94ae6c26fa92cebe178c8e3ea59979ed2.zip
Add no-named-argument command macro match
Diffstat (limited to 'src')
-rw-r--r--src/ext/framework/mod.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/ext/framework/mod.rs b/src/ext/framework/mod.rs
index 39f2148..361fdd8 100644
--- a/src/ext/framework/mod.rs
+++ b/src/ext/framework/mod.rs
@@ -11,8 +11,44 @@ use std::thread;
use ::client::Context;
use ::model::Message;
+/// A macro to generate "named parameters". This is useful to avoid manually
+/// using the "arguments" parameter and manually parsing types.
+///
+/// This is meant for use with the command [`Framework`].
+///
+/// # Examples
+///
+/// Create a regular `ping` command which takes no arguments:
+///
+/// ```rust,ignore
+/// command!(ping(_context, message, _args) {
+/// if let Err(why) = message.reply("Pong!") {
+/// println!("Error sending pong: {:?}", why);
+/// }
+/// });
+/// ```
+///
+/// Create a command named `multiply` which accepts 2 floats and multiplies
+/// them, sending the returned value:
+///
+/// ```rust,ignore
+/// command!(multiply(_context, message, _args, first: f64, second: f64) {
+/// let product = first * second;
+///
+/// if let Err(why) = message.reply(&product.to_string()) {
+/// println!("Error sending product: {:?}", why);
+/// }
+/// });
+/// ```
+///
+/// [`Framework`]: ext/framework/index.html
#[macro_export]
macro_rules! command {
+ ($fname:ident($c:ident, $m:ident, $a:ident) $b:block) => {
+ fn $fname($c: Context, $m: Message, $a: Vec<String>) {
+ $b
+ }
+ };
($fname:ident($c:ident, $m:ident, $a:ident, $($name:ident: $t:ty),*) $b:block) => {
fn $fname($c: Context, $m: Message, $a: Vec<String>) {
let mut i = $a.iter();
@@ -31,7 +67,7 @@ macro_rules! command {
$b
}
- }
+ };
}
/// The type of command being received.