diff options
| author | Austin Hellyer <[email protected]> | 2016-11-06 12:45:00 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-06 12:45:00 -0800 |
| commit | 36958e66fcbc2a3b2ece5203f5705594fc83926f (patch) | |
| tree | 0602565c656bfc7b61df55bbdbd5b1c03f9395a6 /src/ext/framework | |
| parent | Fix framework locking on MessageCreate dispatch (diff) | |
| download | serenity-36958e66fcbc2a3b2ece5203f5705594fc83926f.tar.xz serenity-36958e66fcbc2a3b2ece5203f5705594fc83926f.zip | |
Allow non-prefixed mentions
Allow frameworks to be made and dispatched to that listen for mentions,
but not for prefixes.
Diffstat (limited to 'src/ext/framework')
| -rw-r--r-- | src/ext/framework/mod.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/ext/framework/mod.rs b/src/ext/framework/mod.rs index 3021d5b..68acf0d 100644 --- a/src/ext/framework/mod.rs +++ b/src/ext/framework/mod.rs @@ -33,27 +33,18 @@ impl Framework { pub fn dispatch(&mut self, context: Context, message: Message) { // Determine the point at which the prefix ends, and the command starts. let pos = if let Some(ref prefix) = self.configuration.prefix { - let mut mention_ends = None; - - if let Some(ref mentions) = self.configuration.on_mention { - for mention in mentions { - if !message.content.starts_with(&mention[..]) { - continue; - } - - mention_ends = Some(mention.len() + 1); - - break; - } - } - - if let Some(mention_ends) = mention_ends { + if let Some(mention_ends) = self.find_mention_end(&message.content) { mention_ends } else if !message.content.starts_with(prefix) { return; } else { prefix.len() } + } else if self.configuration.on_mention.is_some() { + match self.find_mention_end(&message.content) { + Some(mention_end) => mention_end, + None => return, + } } else { 0 }; @@ -119,4 +110,18 @@ impl Framework { self } + + fn find_mention_end(&self, content: &str) -> Option<usize> { + if let Some(ref mentions) = self.configuration.on_mention { + for mention in mentions { + if !content.starts_with(&mention[..]) { + continue; + } + + return Some(mention.len() + 1); + } + } + + None + } } |