diff options
| author | Austin Hellyer <[email protected]> | 2016-11-29 20:51:10 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-29 22:27:59 -0800 |
| commit | 93b990d8d1bc9df69b8e27a3db61da570822aad6 (patch) | |
| tree | 6305cf635df90681527a8e736f65ff19f21fd8bc /src/ext/framework | |
| parent | Add more shiny readme badges (diff) | |
| download | serenity-93b990d8d1bc9df69b8e27a3db61da570822aad6.tar.xz serenity-93b990d8d1bc9df69b8e27a3db61da570822aad6.zip | |
Clean up the codebase
Diffstat (limited to 'src/ext/framework')
| -rw-r--r-- | src/ext/framework/command.rs | 15 | ||||
| -rw-r--r-- | src/ext/framework/mod.rs | 32 |
2 files changed, 8 insertions, 39 deletions
diff --git a/src/ext/framework/command.rs b/src/ext/framework/command.rs index e0a4616..46338a1 100644 --- a/src/ext/framework/command.rs +++ b/src/ext/framework/command.rs @@ -1,5 +1,5 @@ use std::sync::Arc; -use super::{CommandType, Configuration}; +use super::Configuration; use ::client::Context; use ::model::Message; @@ -8,15 +8,14 @@ pub type Command = Fn(&Context, &Message, Vec<String>) + Send + Sync; #[doc(hidden)] pub type InternalCommand = Arc<Command>; -pub fn positions(content: &str, conf: &Configuration) - -> Option<(Vec<usize>, CommandType)> { +pub fn positions(content: &str, conf: &Configuration) -> Option<Vec<usize>> { if let Some(ref prefix) = conf.prefix { // Find out if they were mentioned. If not, determine if the prefix // was used. If not, return None. - let (mut positions, kind) = if let Some(mention_end) = find_mention_end(content, conf) { - (vec![mention_end], CommandType::Mention) + let mut positions = if let Some(mention_end) = find_mention_end(content, conf) { + vec![mention_end] } else if content.starts_with(prefix) { - (vec![prefix.len()], CommandType::Prefix) + vec![prefix.len()] } else { return None; }; @@ -29,7 +28,7 @@ pub fn positions(content: &str, conf: &Configuration) positions.insert(0, pos + 1); } - Some((positions, kind)) + Some(positions) } else if conf.on_mention.is_some() { match find_mention_end(content, conf) { Some(mention_end) => { @@ -39,7 +38,7 @@ pub fn positions(content: &str, conf: &Configuration) positions.insert(0, mention_end + 1); } - Some((positions, CommandType::Mention)) + Some(positions) }, None => None, } diff --git a/src/ext/framework/mod.rs b/src/ext/framework/mod.rs index e79bd18..a470550 100644 --- a/src/ext/framework/mod.rs +++ b/src/ext/framework/mod.rs @@ -125,34 +125,6 @@ macro_rules! command { }; } -/// The type of command being received. -/// -/// The [`Mention`] variant is emitted if the bot is being commanded via a -/// mention (`<@USER_ID>` or `<@!USER_ID>`). This can only be emitted if -/// [`Configuration::on_mention`] is set to `true`. -/// -/// The [`Prefix`] variant is emitted if a message starts with the prefix set -/// via [`Configuration::prefix`]. -/// -/// [`Mention`]: #variant.Mention -/// [`Prefix`]: #variant.Prefix -// This is public due to being leaked by [`command::positions`], which is used -// in [`Framework::dispatch`]. It therefore is hidden from the docs, due to -// having no use to users. -// -// [`Framework::dispatch`]: struct.Framework.html#method.dispatch -// [`command::positions`]: command/fn.positions.html -#[derive(Clone, Copy, Debug)] -#[doc(hidden)] -pub enum CommandType { - /// This is emitted if the bot is being commanded via a mention - /// (`<@USER_ID>` or `<@!USER_ID>`). This can only be emitted if - /// [`Configuration::on_mention`] is set to `true`. - Mention, - None, - Prefix, -} - /// A utility for easily managing dispatches to commands. /// /// Refer to the [module-level documentation] for more information. @@ -214,7 +186,6 @@ impl Framework { pub fn configure<F>(mut self, f: F) -> Self where F: FnOnce(Configuration) -> Configuration { self.configuration = f(self.configuration); - self.initialized = true; self } @@ -224,7 +195,7 @@ impl Framework { let res = command::positions(&message.content, &self.configuration); let positions = match res { - Some((positions, _kind)) => positions, + Some(positions) => positions, None => return, }; @@ -358,7 +329,6 @@ impl Framework { where F: Fn(&Context, &Message) -> bool + Send + Sync + 'static, S: Into<String> { self.checks.insert(command.into(), Arc::new(check)); - self.initialized = true; self } |