Skip to content

Commit

Permalink
Refactor command::positions a little
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis committed Aug 3, 2018
1 parent f064d65 commit 2a6c3b1
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/framework/standard/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 2a6c3b1

Please sign in to comment.