aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2018-08-03 22:29:20 +0200
committeracdenisSK <[email protected]>2018-08-03 22:31:01 +0200
commit2a6c3b1d1e24ec7dc3b1f19baf87594e362ded27 (patch)
tree9fe4a7ccfbf6eaeb6a4de1254a70da3922b96d53 /src/framework
parentFix potential dispatch cache deadlocking + log it (diff)
downloadserenity-2a6c3b1d1e24ec7dc3b1f19baf87594e362ded27.tar.xz
serenity-2a6c3b1d1e24ec7dc3b1f19baf87594e362ded27.zip
Refactor `command::positions` a little
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/command.rs19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs
index a6a6074..42264f2 100644
--- a/src/framework/standard/command.rs
+++ b/src/framework/standard/command.rs
@@ -338,15 +338,14 @@ impl Default for CommandOptions {
}
pub fn positions(ctx: &mut Context, msg: &Message, conf: &Configuration) -> Option<Vec<usize>> {
- if !conf.prefixes.is_empty() || conf.dynamic_prefix.is_some() {
- // Find out if they were mentioned. If not, determine if the prefix
- // was used. If not, return None.
- let mut positions: Vec<usize> = vec![];
+ // Mentions have the highest precedence.
+ if let Some(mention_end) = find_mention_end(&msg.content, conf) {
+ return Some(vec![mention_end]); // This can simply be returned without trying to find the end whitespaces as trim will remove it later
+ }
- if let Some(mention_end) = find_mention_end(&msg.content, conf) {
- positions.push(mention_end);
- return Some(positions);
- }
+ if !conf.prefixes.is_empty() || conf.dynamic_prefix.is_some() {
+ // Determine if a prefix was used. Otherwise return None.
+ let mut positions = Vec::new();
// Dynamic prefixes, if present and suitable, always have a higher priority.
if let Some(x) = conf.dynamic_prefix.as_ref().and_then(|f| f(ctx, msg)) {
@@ -390,10 +389,6 @@ pub fn positions(ctx: &mut Context, msg: &Message, conf: &Configuration) -> Opti
}
Some(positions)
- } else if conf.on_mention.is_some() {
- find_mention_end(&msg.content, conf).map(|mention_end| {
- vec![mention_end] // This can simply be returned without trying to find the end whitespaces as trim will remove it later
- })
} else {
None
}