aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml4
-rw-r--r--src/framework/command.rs34
2 files changed, 15 insertions, 23 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 77c5266..cae5581 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -42,11 +42,11 @@ version = "0.2.2"
[dependencies.regex]
optional = true
-regex = "0.2"
+version = "0.2"
[dependencies.itertools]
optional = true
-itertools = "0.6.1"
+version = "0.6.1"
[dependencies.lazy_static]
optional = true
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())
+ })
}