From 2a6c3b1d1e24ec7dc3b1f19baf87594e362ded27 Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Fri, 3 Aug 2018 22:29:20 +0200 Subject: [PATCH] Refactor `command::positions` a little --- src/framework/standard/command.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs index a6a6074dc3f..42264f2b28e 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> { - 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 = 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 }