diff options
| author | Lakelezz <[email protected]> | 2018-08-07 13:46:50 +0200 |
|---|---|---|
| committer | Alex M. M <[email protected]> | 2018-08-07 13:46:50 +0200 |
| commit | 8f128b2c041d5f708378082af3653ff1ee2df919 (patch) | |
| tree | 99690e40545fb71b164383e1ce39ad6fde83406a /src/framework | |
| parent | Do not return Result from main in tests (diff) | |
| download | serenity-8f128b2c041d5f708378082af3653ff1ee2df919.tar.xz serenity-8f128b2c041d5f708378082af3653ff1ee2df919.zip | |
Fix default command upon shortcut prefix and passing sub-commands to default-command (#358)
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/standard/mod.rs | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index 4aa462e..52b955b 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -1043,8 +1043,9 @@ impl Framework for StandardFramework { // than the last matching one, this prevents picking a wrong prefix, // e.g. "f" instead of "ferris" due to "f" having a lower index in the `Vec`. let longest_matching_prefix_len = prefixes.iter().fold(0, |longest_prefix_len, prefix| - if prefix.len() > longest_prefix_len && built.starts_with(prefix) - && (orginal_round.len() == built.len() || command_length > prefix.len() + 1) { + if prefix.len() > longest_prefix_len + && built.starts_with(prefix) + && (orginal_round.len() == prefix.len() || built.get(prefix.len()..prefix.len() + 1) == Some(" ")) { prefix.len() } else { longest_prefix_len @@ -1064,13 +1065,6 @@ impl Framework for StandardFramework { built.clone() }; - let mut args = { - let content = message.content.chars().skip(position).skip_while(|x| x.is_whitespace()) - .skip(command_length).collect::<String>(); - - Args::new(&content.trim(), &self.configuration.delimiters) - }; - let before = self.before.clone(); let after = self.after.clone(); @@ -1079,6 +1073,16 @@ impl Framework for StandardFramework { if let Some(help) = help { let groups = self.groups.clone(); + + // `Args`-construction here inside help-dispatch and the command-dispatch-section + // shall stay identical, please update accordingly upon change. + let mut args = { + let content = message.content.chars().skip(position).skip_while(|x| x.is_whitespace()) + .skip(command_length).collect::<String>(); + + Args::new(&content.trim(), &self.configuration.delimiters) + }; + threadpool.execute(move || { if let Some(before) = before { @@ -1098,13 +1102,21 @@ impl Framework for StandardFramework { } } - if !to_check.is_empty() { if let Some(&CommandOrAlias::Command(ref command)) = group.commands.get(&to_check) { let command = Arc::clone(command); + // `Args`-construction here inside command-dispatch and the help-dispatch + // shall stay identical, please update accordingly upon change. + let mut args = { + let content = message.content.chars().skip(position).skip_while(|x| x.is_whitespace()) + .skip(command_length).collect::<String>(); + + Args::new(&content.trim(), &self.configuration.delimiters) + }; + if let Some(error) = self.should_fail( &mut context, &message, @@ -1149,10 +1161,15 @@ impl Framework for StandardFramework { if let &Some(CommandOrAlias::Command(ref command)) = &group.default_command { let command = Arc::clone(command); + let mut args = { + let content = to_check; + + Args::new(&content.trim(), &self.configuration.delimiters) + }; threadpool.execute(move || { if let Some(before) = before { - if !(before)(&mut context, &message, &to_check) { + if !(before)(&mut context, &message, &args.full()) { return; } } |