aboutsummaryrefslogtreecommitdiff
path: root/src/ext/framework/create_group.rs
diff options
context:
space:
mode:
authortaavi? <[email protected]>2016-12-29 23:21:57 +0300
committerzeyla <[email protected]>2016-12-29 12:21:57 -0800
commitf96b6cc5e1e0383fd2de826c8ffd95565d5ca4fb (patch)
treee49ca34f9a6ce8bda865bed82c8bd2519c4cbcc4 /src/ext/framework/create_group.rs
parentRemove use of struct pattern match (diff)
downloadserenity-f96b6cc5e1e0383fd2de826c8ffd95565d5ca4fb.tar.xz
serenity-f96b6cc5e1e0383fd2de826c8ffd95565d5ca4fb.zip
Add command alias support and command.example
Diffstat (limited to 'src/ext/framework/create_group.rs')
-rw-r--r--src/ext/framework/create_group.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/ext/framework/create_group.rs b/src/ext/framework/create_group.rs
index 8374e8b..465224d 100644
--- a/src/ext/framework/create_group.rs
+++ b/src/ext/framework/create_group.rs
@@ -1,4 +1,4 @@
-pub use ext::framework::command::{Command, CommandType, CommandGroup};
+pub use ext::framework::command::{Command, CommandType, CommandGroup, CommandOrAlias};
pub use ext::framework::create_command::CreateCommand;
use std::default::Default;
@@ -29,7 +29,15 @@ impl CreateGroup {
where F: FnOnce(CreateCommand) -> CreateCommand {
let cmd = f(CreateCommand(Command::default())).0;
- self.0.commands.insert(command_name.to_owned(), Arc::new(cmd));
+ for n in &cmd.aliases {
+ if let Some(ref prefix) = self.0.prefix {
+ self.0.commands.insert(format!("{} {}", prefix, n.to_owned()), CommandOrAlias::Alias(format!("{} {}", prefix, command_name.to_string())));
+ } else {
+ self.0.commands.insert(n.to_owned(), CommandOrAlias::Alias(command_name.to_string()));
+ }
+ }
+
+ self.0.commands.insert(command_name.to_owned(), CommandOrAlias::Command(Arc::new(cmd)));
self
}
@@ -40,7 +48,7 @@ impl CreateGroup {
where F: Fn(&Context, &Message, Vec<String>) -> Result<(), String> + Send + Sync + 'static {
let cmd = Arc::new(Command::new(f));
- self.0.commands.insert(command_name.to_owned(), cmd);
+ self.0.commands.insert(command_name.to_owned(), CommandOrAlias::Command(cmd));
self
}
@@ -50,6 +58,8 @@ impl CreateGroup {
/// we'd call a subcommand named "hibiki" by sending "~image hibiki".
///
/// **Note**: serenity automatically puts a space after group prefix.
+ ///
+ /// **Note**: It's suggested to call this first when making a group.
pub fn prefix(mut self, desc: &str) -> Self {
self.0.prefix = Some(desc.to_owned());