aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentFix presence updates (diff)
downloadserenity-cb072aab60ac67bc4d52aed3554300c1c5e83081.tar.xz
serenity-cb072aab60ac67bc4d52aed3554300c1c5e83081.zip
Fix tests (#145)
Diffstat (limited to 'src')
-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
-rw-r--r--src/lib.rs2
-rw-r--r--src/model/channel/message.rs1
-rw-r--r--src/model/gateway.rs9
-rw-r--r--src/model/misc.rs38
10 files changed, 97 insertions, 88 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)
},
diff --git a/src/lib.rs b/src/lib.rs
index 56d22ae..230ab68 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -107,7 +107,7 @@ extern crate flate2;
extern crate serde;
extern crate parking_lot;
-#[cfg(feature="framework")]
+#[cfg(feature = "framework")]
extern crate vec_shift;
#[cfg(feature = "voice")]
extern crate byteorder;
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs
index dc6dcfa..27f4e31 100644
--- a/src/model/channel/message.rs
+++ b/src/model/channel/message.rs
@@ -82,6 +82,7 @@ impl Message {
/// #
/// # fn main() {
/// # use serenity::prelude::*;
+ /// # use serenity::framework::standard::Args;
/// # struct Handler;
/// #
/// # impl EventHandler for Handler {}
diff --git a/src/model/gateway.rs b/src/model/gateway.rs
index 6153abb..1b3a40b 100644
--- a/src/model/gateway.rs
+++ b/src/model/gateway.rs
@@ -47,6 +47,7 @@ impl Game {
/// ```rust,no_run
/// # #[macro_use] extern crate serenity;
/// #
+ /// use serenity::framework::standard::Args;
/// use serenity::model::Game;
///
/// command!(game(ctx, _msg, args) {
@@ -75,12 +76,14 @@ impl Game {
/// ```rust,no_run
/// # #[macro_use] extern crate serenity;
/// #
+ /// use serenity::framework::standard::Args;
/// use serenity::model::Game;
///
/// // Assumes command has min_args set to 2.
- /// command!(stream(ctx, _msg, args, stream: String) {
- /// let name = args[1..].join(" ");
- /// ctx.set_game(Game::streaming(&name, &stream));
+ /// command!(stream(ctx, _msg, args) {
+ /// # let stream_url = String::from("");
+ /// let name = args.full();
+ /// ctx.set_game(Game::streaming(&name, &stream_url));
/// });
/// #
/// # fn main() {}
diff --git a/src/model/misc.rs b/src/model/misc.rs
index 8106c40..dee915e 100644
--- a/src/model/misc.rs
+++ b/src/model/misc.rs
@@ -60,25 +60,23 @@ impl Mentionable for User {
#[derive(Debug)]
pub enum UserParseError {
NotPresentInCache,
- InvalidUsername
+ InvalidUsername,
}
#[cfg(all(feature = "model", feature = "utils"))]
impl fmt::Display for UserParseError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.description())
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) }
}
#[cfg(all(feature = "cache", feature = "utils"))]
impl StdError for UserParseError {
fn description(&self) -> &str {
use self::UserParseError::*;
-
+
match *self {
NotPresentInCache => "not present in cache",
- InvalidUsername => "invalid username"
+ InvalidUsername => "invalid username",
}
}
}
@@ -108,16 +106,14 @@ pub enum UserIdParseError {
#[cfg(all(feature = "model", feature = "utils"))]
impl fmt::Display for UserIdParseError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.description())
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) }
}
#[cfg(all(feature = "cache", feature = "utils"))]
impl StdError for UserIdParseError {
fn description(&self) -> &str {
use self::UserIdParseError::*;
-
+
match *self {
NotPresentInCache => "not present in cache",
}
@@ -129,7 +125,9 @@ impl FromStr for UserId {
type Err = UserIdParseError;
fn from_str(s: &str) -> StdResult<Self, Self::Err> {
- utils::parse_username(s).ok_or_else(|| UserIdParseError::NotPresentInCache).map(UserId)
+ utils::parse_username(s)
+ .ok_or_else(|| UserIdParseError::NotPresentInCache)
+ .map(UserId)
}
}
@@ -142,19 +140,17 @@ pub enum RoleParseError {
#[cfg(all(feature = "model", feature = "utils"))]
impl fmt::Display for RoleParseError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.description())
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) }
}
#[cfg(all(feature = "cache", feature = "utils"))]
impl StdError for RoleParseError {
fn description(&self) -> &str {
use self::RoleParseError::*;
-
+
match *self {
NotPresentInCache => "not present in cache",
- InvalidRole => "invalid role"
+ InvalidRole => "invalid role",
}
}
}
@@ -184,16 +180,14 @@ pub enum RoleIdParseError {
#[cfg(all(feature = "model", feature = "utils"))]
impl fmt::Display for RoleIdParseError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.description())
- }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.description()) }
}
#[cfg(all(feature = "cache", feature = "utils"))]
impl StdError for RoleIdParseError {
fn description(&self) -> &str {
use self::RoleIdParseError::*;
-
+
match *self {
NotPresentInCache => "not present in cache",
}
@@ -205,7 +199,9 @@ impl FromStr for RoleId {
type Err = RoleIdParseError;
fn from_str(s: &str) -> StdResult<Self, Self::Err> {
- utils::parse_role(s).ok_or_else(|| RoleIdParseError::NotPresentInCache).map(RoleId)
+ utils::parse_role(s)
+ .ok_or_else(|| RoleIdParseError::NotPresentInCache)
+ .map(RoleId)
}
}