diff options
| author | Lakelezz <[email protected]> | 2018-07-15 16:49:25 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-07-15 16:49:25 +0200 |
| commit | 305d2008216b5351d9fdd357381027ea42f4740b (patch) | |
| tree | de151f91f3774c60abbdaf6cb30831f77ef8c354 /src/framework/standard/create_group.rs | |
| parent | Add checks for groups (#349) (diff) | |
| download | serenity-305d2008216b5351d9fdd357381027ea42f4740b.tar.xz serenity-305d2008216b5351d9fdd357381027ea42f4740b.zip | |
Support multiple prefixes for command-groups (#343)
Diffstat (limited to 'src/framework/standard/create_group.rs')
| -rw-r--r-- | src/framework/standard/create_group.rs | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/framework/standard/create_group.rs b/src/framework/standard/create_group.rs index c99b829..91eef78 100644 --- a/src/framework/standard/create_group.rs +++ b/src/framework/standard/create_group.rs @@ -13,8 +13,10 @@ pub use super::{ }; use client::Context; -use model::channel::Message; -use model::Permissions; +use model::{ + channel::Message, + Permissions, +}; use std::sync::Arc; /// Used to create command groups @@ -56,11 +58,15 @@ impl CreateGroup { let cmd = f(self.build_command()).finish(); for n in &cmd.options().aliases { - if let Some(ref prefix) = self.0.prefix { - self.0.commands.insert( - format!("{} {}", prefix, n.to_string()), - CommandOrAlias::Alias(format!("{} {}", prefix, command_name.to_string())), - ); + + if let Some(ref prefixes) = self.0.prefixes { + + for prefix in prefixes { + self.0.commands.insert( + format!("{} {}", prefix, n.to_string()), + CommandOrAlias::Alias(format!("{} {}", prefix, command_name.to_string())), + ); + } } else { self.0.commands.insert( n.to_string(), @@ -106,8 +112,20 @@ impl CreateGroup { /// **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_string()); + pub fn prefix(mut self, prefix: &str) -> Self { + self.0.prefixes = Some(vec![prefix.to_string()]); + + self + } + + /// Sets prefixes to respond to. Each can be a string slice of any + /// non-zero length. + /// + /// **Note**: serenity automatically puts a space after group prefix. + /// + /// **Note**: It's suggested to call this first when making a group. + pub fn prefixes<T: ToString, I: IntoIterator<Item=T>>(mut self, prefixes: I) -> Self { + self.0.prefixes = Some(prefixes.into_iter().map(|prefix| prefix.to_string()).collect()); self } |