diff options
| author | acdenisSK <[email protected]> | 2017-08-14 13:02:50 +0200 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-08-14 13:02:50 +0200 |
| commit | df98814652e6e74da7f63c39c92f4785bbf01e6e (patch) | |
| tree | 0de51cb01b45e03250dbf1d0a1c5df5eacb84ef1 /src/framework/command.rs | |
| parent | Fix string delimiters (#134) (diff) | |
| download | serenity-df98814652e6e74da7f63c39c92f4785bbf01e6e.tar.xz serenity-df98814652e6e74da7f63c39c92f4785bbf01e6e.zip | |
`$crate_name` => `version`, and a few adjustements
Diffstat (limited to 'src/framework/command.rs')
| -rw-r--r-- | src/framework/command.rs | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/framework/command.rs b/src/framework/command.rs index 19b6756..7a44bc4 100644 --- a/src/framework/command.rs +++ b/src/framework/command.rs @@ -130,33 +130,25 @@ pub fn positions(ctx: &mut Context, msg: &Message, conf: &Configuration) -> Opti Some(positions) } else if conf.on_mention.is_some() { - match find_mention_end(&msg.content, conf) { - Some(mention_end) => { - let mut positions = vec![mention_end]; + find_mention_end(&msg.content, conf).map(|mention_end| { + let mut positions = vec![mention_end]; - if conf.allow_whitespace { - positions.insert(0, mention_end + 1); - } + if conf.allow_whitespace { + positions.insert(0, mention_end + 1); + } - Some(positions) - }, - None => None, - } + positions + }) } else { None } } fn find_mention_end(content: &str, conf: &Configuration) -> Option<usize> { - if let Some(ref mentions) = conf.on_mention { - for mention in mentions { - if !content.starts_with(&mention[..]) { - continue; - } - - return Some(mention.len()); - } - } - - None + conf.on_mention.as_ref().and_then(|mentions| { + mentions + .iter() + .find(|mention| content.starts_with(&mention[..])) + .map(|m| m.len()) + }) } |