aboutsummaryrefslogtreecommitdiff
path: root/src/ext/framework/create_command.rs
diff options
context:
space:
mode:
authorIllia <[email protected]>2016-12-13 21:26:29 +0200
committerzeyla <[email protected]>2016-12-13 11:26:29 -0800
commitdaf92eda815b8f539f6d759ab48cf7a70513915f (patch)
tree36145f5095e7af6fb725635dd104e9d9d3f0ea62 /src/ext/framework/create_command.rs
parentFix readme typo (diff)
downloadserenity-daf92eda815b8f539f6d759ab48cf7a70513915f.tar.xz
serenity-daf92eda815b8f539f6d759ab48cf7a70513915f.zip
Implement command groups and buckets
* Implement command groups * change to ref mut * Implement framework API. * Remove commands field * Make it all work * Make example use command groups * Requested changes * Implement adding buckets * Add ratelimit check function * Finish everything * Fix voice example * Actually fix it * Fix doc tests * Switch to result * Savage examples * Fix docs * Fixes * Accidental push * 👀 * Fix an example * fix some example * Small cleanup * Abstract ratelimit bucket logic
Diffstat (limited to 'src/ext/framework/create_command.rs')
-rw-r--r--src/ext/framework/create_command.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/ext/framework/create_command.rs b/src/ext/framework/create_command.rs
index 6d40592..e3faffd 100644
--- a/src/ext/framework/create_command.rs
+++ b/src/ext/framework/create_command.rs
@@ -1,4 +1,4 @@
-pub use ext::framework::command::{Command, CommandType};
+pub use super::{Command, CommandType, CommandGroup};
use std::collections::HashMap;
use std::default::Default;
@@ -32,8 +32,10 @@ impl CreateCommand {
/// .desc("Replies to a ping with a pong")
/// .exec(ping)));
///
- /// fn ping(context: &Context, _message: &Message, _args: Vec<String>) {
- /// context.say("Pong!");
+ /// fn ping(context: &Context, _message: &Message, _args: Vec<String>) -> Result<(), String> {
+ /// let _ = context.say("Pong!");
+ ///
+ /// Ok(())
/// }
///
/// fn owner_check(_context: &Context, message: &Message) -> bool {
@@ -55,6 +57,13 @@ impl CreateCommand {
self
}
+ /// Adds a ratelimit bucket.
+ pub fn bucket(mut self, bucket: &str) -> Self {
+ self.0.bucket = Some(bucket.to_owned());
+
+ self
+ }
+
/// Whether command should be displayed in help list or not, used by other commands.
pub fn help_available(mut self, help_available: bool) -> Self {
self.0.help_available = help_available;
@@ -98,12 +107,13 @@ impl CreateCommand {
}
/// A function that can be called when a command is received.
+ /// You can return Err(string) if there's an error.
///
/// See [`exec_str`] if you _only_ need to return a string on command use.
///
/// [`exec_str`]: #method.exec_str
pub fn exec<F>(mut self, func: F) -> Self
- where F: Fn(&Context, &Message, Vec<String>) + Send + Sync + 'static {
+ where F: Fn(&Context, &Message, Vec<String>) -> Result<(), String> + Send + Sync + 'static {
self.0.exec = CommandType::Basic(Box::new(func));
self
@@ -112,8 +122,10 @@ impl CreateCommand {
/// Sets a function that's called when a command is called that can access
/// the internal HashMap of usages, used specifically for creating a help
/// command.
+ ///
+ /// You can return Err(string) if there's an error.
pub fn exec_help<F>(mut self, f: F) -> Self
- where F: Fn(&Context, &Message, HashMap<String, Arc<Command>>, Vec<String>) + Send + Sync + 'static {
+ where F: Fn(&Context, &Message, HashMap<String, Arc<CommandGroup>>, Vec<String>) -> Result<(), String> + Send + Sync + 'static {
self.0.exec = CommandType::WithCommands(Box::new(f));
self
@@ -165,11 +177,12 @@ impl Default for Command {
fn default() -> Command {
Command {
checks: Vec::default(),
- exec: CommandType::Basic(Box::new(|_, _, _| {})),
+ exec: CommandType::Basic(Box::new(|_, _, _| Ok(()))),
desc: None,
usage: None,
use_quotes: true,
min_args: None,
+ bucket: None,
max_args: None,
required_permissions: Permissions::empty(),
dm_only: false,