diff options
| author | acdenisSK <[email protected]> | 2017-09-01 19:21:38 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-09-01 19:21:38 +0200 |
| commit | deee38d87d71a918b6d8270dbfaffeb0a7234508 (patch) | |
| tree | c1d5e3c92fc43ba50e3245192d1531b1945d50d4 /src/framework | |
| parent | Add num_args (#156) (diff) | |
| download | serenity-deee38d87d71a918b6d8270dbfaffeb0a7234508.tar.xz serenity-deee38d87d71a918b6d8270dbfaffeb0a7234508.zip | |
Add case insensitivity
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/standard/configuration.rs | 12 | ||||
| -rw-r--r-- | src/framework/standard/mod.rs | 8 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/framework/standard/configuration.rs b/src/framework/standard/configuration.rs index 491bbc4..611e748 100644 --- a/src/framework/standard/configuration.rs +++ b/src/framework/standard/configuration.rs @@ -59,6 +59,8 @@ pub struct Configuration { pub prefixes: Vec<String>, #[doc(hidden)] pub delimiters: Vec<String>, + #[doc(hidden)] + pub case_insensitive: bool, } impl Configuration { @@ -421,6 +423,14 @@ impl Configuration { self } + + /// Whether the framework shouldn't care about the user's input if it's: `~command`, `~Command`, `~COMMAND`. + /// Setting this to `true` will result in *all* command names to be case insensitive. + pub fn case_insensitivity(mut self, cs: bool) -> Self { + self.case_insensitive = cs; + + self + } } impl Default for Configuration { @@ -431,6 +441,7 @@ impl Default for Configuration { /// - **on_mention** to `false` (basically) /// - **prefix** to `None` /// - **delimiters** to vec![" "] + /// - **case_insensitive** to `false` fn default() -> Configuration { Configuration { depth: 5, @@ -445,6 +456,7 @@ impl Default for Configuration { disabled_commands: HashSet::default(), allow_dm: true, ignore_webhooks: true, + case_insensitive: false, delimiters: vec![" ".to_string()], } } diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index 04ebc5f..a8570e6 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -861,7 +861,7 @@ impl Framework for StandardFramework { built = points_to.to_owned(); } - let to_check = if let Some(ref prefix) = group.prefix { + let mut to_check = if let Some(ref prefix) = group.prefix { if built.starts_with(prefix) && command_length > prefix.len() + 1 { built[(prefix.len() + 1)..].to_owned() } else { @@ -871,6 +871,12 @@ impl Framework for StandardFramework { built.clone() }; + to_check = if self.configuration.case_insensitive { + to_check.to_lowercase() + } else { + to_check + }; + if let Some(&CommandOrAlias::Command(ref command)) = group.commands.get(&to_check) { let before = self.before.clone(); |