aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authorMaiddog <[email protected]>2017-08-22 06:27:10 -0500
committeralex <[email protected]>2017-08-22 13:27:10 +0200
commitcb072aab60ac67bc4d52aed3554300c1c5e83081 (patch)
treefc00dd5d91b989582e10a93afb4713f1fbd6c88f /src/framework
parentFix presence updates (diff)
downloadserenity-cb072aab60ac67bc4d52aed3554300c1c5e83081.tar.xz
serenity-cb072aab60ac67bc4d52aed3554300c1c5e83081.zip
Fix tests (#145)
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/mod.rs4
-rw-r--r--src/framework/standard/args.rs97
-rw-r--r--src/framework/standard/command.rs2
-rw-r--r--src/framework/standard/create_command.rs7
-rw-r--r--src/framework/standard/create_group.rs5
-rw-r--r--src/framework/standard/mod.rs20
6 files changed, 72 insertions, 63 deletions
diff --git a/src/framework/mod.rs b/src/framework/mod.rs
index c59c8a2..678b5dc 100644
--- a/src/framework/mod.rs
+++ b/src/framework/mod.rs
@@ -54,7 +54,7 @@
//!
//! [`Client::with_framework`]: ../client/struct.Client.html#method.with_framework
-#[cfg(feature="standard_framework")]
+#[cfg(feature = "standard_framework")]
pub mod standard;
#[cfg(feature = "standard_framework")]
@@ -64,7 +64,7 @@ use client::Context;
use model::Message;
use tokio_core::reactor::Handle;
-#[cfg(feature="standard_framework")]
+#[cfg(feature = "standard_framework")]
use model::UserId;
/// This trait allows for serenity to either use its builtin framework, or yours.
diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs
index 020ce6d..f08dd48 100644
--- a/src/framework/standard/args.rs
+++ b/src/framework/standard/args.rs
@@ -8,7 +8,8 @@ use utils::parse_quotes;
pub enum Error {
/// "END-OF-STRING", more precisely, there isn't anything to parse anymore.
Eos,
- /// A parsing operation failed; the error in it can be of any returned from the `FromStr` trait.
+ /// A parsing operation failed; the error in it can be of any returned from the `FromStr`
+ /// trait.
Parse(Box<StdError>),
}
@@ -27,98 +28,112 @@ impl Args {
delimiter_split: message.split(delimiter).map(|s| s.to_string()).collect(),
}
}
-
- /// Removes the first element, parses it to a specific type if necessary, returns.
- pub fn single<T: FromStr>(&mut self) -> Result<T> where T::Err: StdError + 'static {
+
+ /// Removes the first element, parses it to a specific type if necessary, returns.
+ pub fn single<T: FromStr>(&mut self) -> Result<T>
+ where T::Err: StdError + 'static {
if self.delimiter_split.is_empty() {
- return Err(Error::Eos);
+ return Err(Error::Eos);
}
-
- self.delimiter_split.shift()
+
+ self.delimiter_split
+ .shift()
.ok_or(Error::Eos)?
.parse::<T>()
.map_err(|e| Error::Parse(Box::new(e)))
}
-
+
/// Like [`single`], but doesn't remove the element.
///
/// [`single`]: #method.single
- pub fn single_n<T: FromStr>(&mut self) -> Result<T> where T::Err: StdError + 'static {
+ pub fn single_n<T: FromStr>(&mut self) -> Result<T>
+ where T::Err: StdError + 'static {
if self.delimiter_split.is_empty() {
- return Err(Error::Eos);
+ return Err(Error::Eos);
}
-
- self.delimiter_split.get(0)
+
+ self.delimiter_split
+ .get(0)
.ok_or(Error::Eos)?
.parse::<T>()
.map_err(|e| Error::Parse(Box::new(e)))
}
-
+
/// Skips if there's a first element, but also returns it.
- pub fn skip(&mut self) -> Option<String> {
- self.delimiter_split.shift()
- }
-
+ pub fn skip(&mut self) -> Option<String> { self.delimiter_split.shift() }
+
/// Like [`skip`], but allows for multiple at once.
///
/// [`skip`]: #method.skip
pub fn skip_for(&mut self, i: u32) -> Option<Vec<String>> {
let mut vec = Vec::with_capacity(i as usize);
-
+
for _ in 0..i {
vec.push(match self.delimiter_split.shift() {
Some(x) => x,
None => return None,
});
}
-
+
Some(vec)
}
-
+
/// Like [`single`], but takes quotes into account.
///
/// [`single`]: #method.single
- pub fn single_quoted<T: FromStr>(&mut self) -> Result<T> where T::Err: StdError + 'static {
- parse_quotes(&self.delimiter_split.shift().ok_or(Error::Eos)?).remove(0).parse::<T>().map_err(|e| Error::Parse(Box::new(e)))
+ pub fn single_quoted<T: FromStr>(&mut self) -> Result<T>
+ where T::Err: StdError + 'static {
+ parse_quotes(&self.delimiter_split.shift().ok_or(Error::Eos)?)
+ .remove(0)
+ .parse::<T>()
+ .map_err(|e| Error::Parse(Box::new(e)))
}
-
+
/// Like [`single_quoted`], but doesn't remove the element.
///
/// [`single_quoted`]: #method.single_quoted
- pub fn single_quoted_n<T: FromStr>(&mut self) -> Result<T> where T::Err: StdError + 'static {
- parse_quotes(&self.delimiter_split.get(0).ok_or(Error::Eos)?).remove(0).parse::<T>().map_err(|e| Error::Parse(Box::new(e)))
+ pub fn single_quoted_n<T: FromStr>(&mut self) -> Result<T>
+ where T::Err: StdError + 'static {
+ parse_quotes(&self.delimiter_split.get(0).ok_or(Error::Eos)?)
+ .remove(0)
+ .parse::<T>()
+ .map_err(|e| Error::Parse(Box::new(e)))
}
-
+
/// Like [`list`], but takes quotes into account.
///
/// [`list`]: #method.list
- pub fn multiple_quoted<T: FromStr>(self) -> Result<Vec<T>> where T::Err: StdError + 'static {
+ pub fn multiple_quoted<T: FromStr>(self) -> Result<Vec<T>>
+ where T::Err: StdError + 'static {
if self.delimiter_split.is_empty() {
return Err(Error::Eos);
}
-
- parse_quotes(&self.delimiter_split.join(&self.delimiter)).into_iter().map(|s| s.parse::<T>().map_err(|e| Error::Parse(Box::new(e)))).collect()
+
+ parse_quotes(&self.delimiter_split.join(&self.delimiter))
+ .into_iter()
+ .map(|s| s.parse::<T>().map_err(|e| Error::Parse(Box::new(e))))
+ .collect()
}
-
+
/// Empty outs the internal vector while parsing (if necessary) and returning them
- pub fn list<T: FromStr>(self) -> Result<Vec<T>> where T::Err: StdError + 'static {
+ pub fn list<T: FromStr>(self) -> Result<Vec<T>>
+ where T::Err: StdError + 'static {
if self.delimiter_split.is_empty() {
return Err(Error::Eos);
}
-
- self.delimiter_split.into_iter().map(|s| s.parse::<T>().map_err(|e| Error::Parse(Box::new(e)))).collect()
+
+ self.delimiter_split
+ .into_iter()
+ .map(|s| s.parse::<T>().map_err(|e| Error::Parse(Box::new(e))))
+ .collect()
}
-
+
/// This method is just `internal_vector.join(delimiter)`
- pub fn full(&self) -> String {
- self.delimiter_split.join(&self.delimiter)
- }
+ pub fn full(&self) -> String { self.delimiter_split.join(&self.delimiter) }
}
impl ::std::ops::Deref for Args {
type Target = [String];
- fn deref(&self) -> &Self::Target {
- &self.delimiter_split
- }
-} \ No newline at end of file
+ fn deref(&self) -> &Self::Target { &self.delimiter_split }
+}
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs
index d8c2321..22a82ce 100644
--- a/src/framework/standard/command.rs
+++ b/src/framework/standard/command.rs
@@ -1,5 +1,5 @@
use std::sync::Arc;
-use super::{Configuration, Args};
+use super::{Args, Configuration};
use client::Context;
use model::{Message, Permissions};
use std::collections::HashMap;
diff --git a/src/framework/standard/create_command.rs b/src/framework/standard/create_command.rs
index f6be992..0a467e1 100644
--- a/src/framework/standard/create_command.rs
+++ b/src/framework/standard/create_command.rs
@@ -38,7 +38,7 @@ impl CreateCommand {
/// # struct Handler;
/// # impl EventHandler for Handler {}
/// use serenity::client::{Client, Context};
- /// use serenity::framework::standard::{Command, StandardFramework};
+ /// use serenity::framework::standard::{Args, Command, StandardFramework};
/// use serenity::model::Message;
/// use std::env;
/// use std::sync::Arc;
@@ -103,10 +103,7 @@ impl CreateCommand {
///
/// [`exec_str`]: #method.exec_str
pub fn exec<F>(mut self, func: F) -> Self
- where F: Fn(&mut Context, &Message, Args) -> Result<(), String>
- + Send
- + Sync
- + 'static {
+ where F: Fn(&mut Context, &Message, Args) -> Result<(), String> + Send + Sync + 'static {
self.0.exec = CommandType::Basic(Box::new(func));
self
diff --git a/src/framework/standard/create_group.rs b/src/framework/standard/create_group.rs
index fabcc50..013ba67 100644
--- a/src/framework/standard/create_group.rs
+++ b/src/framework/standard/create_group.rs
@@ -58,10 +58,7 @@ impl CreateGroup {
/// Adds a command to group with simplified API.
/// You can return Err(string) if there's an error.
pub fn on<F>(mut self, command_name: &str, f: F) -> Self
- where F: Fn(&mut Context, &Message, Args) -> Result<(), String>
- + Send
- + Sync
- + 'static {
+ where F: Fn(&mut Context, &Message, Args) -> Result<(), String> + Send + Sync + 'static {
let cmd = Arc::new(Command::new(f));
self.0.commands.insert(
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs
index 87880f8..0a29b59 100644
--- a/src/framework/standard/mod.rs
+++ b/src/framework/standard/mod.rs
@@ -562,6 +562,7 @@ impl StandardFramework {
/// #
/// # fn main() {
/// # use serenity::prelude::*;
+ /// # use serenity::framework::standard::Args;
/// # struct Handler;
/// #
/// # impl EventHandler for Handler {}
@@ -577,8 +578,7 @@ impl StandardFramework {
/// # }
/// ```
pub fn on<F, S>(mut self, command_name: S, f: F) -> Self
- where F: Fn(&mut Context, &Message, Args) -> Result<(), String> + 'static,
- S: Into<String> {
+ where F: Fn(&mut Context, &Message, Args) -> Result<(), String> + 'static, S: Into<String> {
{
let ungrouped = self.groups.entry("Ungrouped".to_owned()).or_insert_with(
|| {
@@ -702,7 +702,8 @@ impl StandardFramework {
/// #
/// # impl EventHandler for Handler {}
/// # let mut client = Client::new("token", Handler);
- /// use serenity::framework::standard::DispatchError::{NotEnoughArguments, TooManyArguments};
+ /// use serenity::framework::standard::DispatchError::{NotEnoughArguments,
+ /// TooManyArguments};
/// use serenity::framework::StandardFramework;
///
/// client.with_framework(StandardFramework::new()
@@ -882,13 +883,14 @@ impl Framework for StandardFramework {
let mut args = {
let mut content = message.content[position..].trim();
- content = content[command_length..].trim();
-
- let delimiter = self.configuration.delimiters
+ content = content[command_length..].trim();
+
+ let delimiter = self.configuration
+ .delimiters
.iter()
.find(|&d| content.contains(d))
.map_or(" ", |s| s.as_str());
-
+
Args::new(&content, delimiter)
};
@@ -919,9 +921,7 @@ impl Framework for StandardFramework {
Ok(())
},
- CommandType::Basic(ref x) => {
- (x)(&mut context, &message, args)
- },
+ CommandType::Basic(ref x) => (x)(&mut context, &message, args),
CommandType::WithCommands(ref x) => {
(x)(&mut context, &message, groups, args)
},