aboutsummaryrefslogtreecommitdiff
path: root/src/framework/standard/mod.rs
diff options
context:
space:
mode:
authorLakelezz <[email protected]>2018-07-21 01:48:12 +0200
committerGitHub <[email protected]>2018-07-21 01:48:12 +0200
commit40c8248d107b3c6cad785502e6d619669aba6431 (patch)
treec8553c60b7e9b1367c4d6d51fcbc4e00143cd979 /src/framework/standard/mod.rs
parentDo not suggest command if no command is actually related to input. (#350) (diff)
downloadserenity-40c8248d107b3c6cad785502e6d619669aba6431.tar.xz
serenity-40c8248d107b3c6cad785502e6d619669aba6431.zip
Add default-commands for command-groups (#351)
Diffstat (limited to 'src/framework/standard/mod.rs')
-rw-r--r--src/framework/standard/mod.rs44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs
index 1d7158a..495f9be 100644
--- a/src/framework/standard/mod.rs
+++ b/src/framework/standard/mod.rs
@@ -988,9 +988,9 @@ impl Framework for StandardFramework {
None => return,
};
- 'outer: for position in positions {
+ 'outer: for (index, position) in positions.iter().enumerate() {
let mut built = String::new();
- let round = message.content.chars().skip(position).collect::<String>();
+ let round = message.content.chars().skip(*position).collect::<String>();
let mut round = round.trim().split_whitespace(); // Call to `trim` causes the related bug under the main bug #206 - where the whitespace settings are ignored. The fix is implemented as an additional check inside command::positions
for i in 0..self.configuration.depth {
@@ -1027,15 +1027,18 @@ 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) && command_length > prefix.len() + 1 {
+ if prefix.len() > longest_prefix_len && built.starts_with(prefix)
+ && (index + 1 == positions.len() || command_length > prefix.len() + 1) {
prefix.len()
} else {
longest_prefix_len
}
);
- if longest_matching_prefix_len > 0 {
- built[(longest_matching_prefix_len + 1)..].to_string()
+ if longest_matching_prefix_len == built.len() {
+ String::new()
+ } else if longest_matching_prefix_len > 0 {
+ built[longest_matching_prefix_len + 1..].to_string()
} else {
continue;
}
@@ -1044,7 +1047,7 @@ impl Framework for StandardFramework {
};
let mut args = {
- let content = message.content.chars().skip(position).skip_while(|x| x.is_whitespace())
+ 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)
@@ -1053,7 +1056,34 @@ impl Framework for StandardFramework {
let before = self.before.clone();
let after = self.after.clone();
- if to_check == "help" {
+ if to_check.is_empty() {
+
+ if let Some(CommandOrAlias::Command(ref command)) = &group.default_command {
+ let command = Arc::clone(command);
+
+ threadpool.execute(move || {
+ if let Some(before) = before {
+ if !(before)(&mut context, &message, &built) {
+ return;
+ }
+ }
+
+ if !command.before(&mut context, &message) {
+ return;
+ }
+
+ let result = command.execute(&mut context, &message, args);
+
+ command.after(&mut context, &message, &result);
+
+ if let Some(after) = after {
+ (after)(&mut context, &message, &built, result);
+ }
+ });
+
+ return;
+ }
+ } else if to_check == "help" {
let help = self.help.clone();
if let Some(help) = help {