aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-08-18 16:14:32 -0700
committerZeyla Hellyer <[email protected]>2017-08-18 17:52:53 -0700
commite4113570967a1fb13539efbfa2cf7285b19d95ba (patch)
tree06bb020fcfaa5f8323454dfb525272314a900186 /src/framework
parentMove Clippy lints to a cfg_attr (diff)
downloadserenity-e4113570967a1fb13539efbfa2cf7285b19d95ba.tar.xz
serenity-e4113570967a1fb13539efbfa2cf7285b19d95ba.zip
Apply rustfmt
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/buckets.rs6
-rw-r--r--src/framework/command.rs5
-rw-r--r--src/framework/configuration.rs8
-rw-r--r--src/framework/create_command.rs20
-rw-r--r--src/framework/create_group.rs11
-rw-r--r--src/framework/help_commands.rs18
-rw-r--r--src/framework/mod.rs108
7 files changed, 113 insertions, 63 deletions
diff --git a/src/framework/buckets.rs b/src/framework/buckets.rs
index 4719b85..f2c4486 100644
--- a/src/framework/buckets.rs
+++ b/src/framework/buckets.rs
@@ -31,9 +31,9 @@ pub(crate) struct Bucket {
impl Bucket {
pub fn take(&mut self, user_id: u64) -> i64 {
let time = Utc::now().timestamp();
- let user = self.users
- .entry(user_id)
- .or_insert_with(MemberRatelimit::default);
+ let user = self.users.entry(user_id).or_insert_with(
+ MemberRatelimit::default,
+ );
if let Some((timespan, limit)) = self.ratelimit.limit {
if (user.tickets + 1) > limit {
diff --git a/src/framework/command.rs b/src/framework/command.rs
index 3528e85..01c4c5e 100644
--- a/src/framework/command.rs
+++ b/src/framework/command.rs
@@ -6,7 +6,10 @@ use std::collections::HashMap;
pub type Check = Fn(&mut Context, &Message, &[String], &Arc<Command>) -> bool + 'static;
pub type Exec = Fn(&mut Context, &Message, Vec<String>, String) -> Result<(), String> + 'static;
-pub type Help = Fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, &[String])
+pub type Help = Fn(&mut Context,
+ &Message,
+ HashMap<String, Arc<CommandGroup>>,
+ &[String])
-> Result<(), String>
+ 'static;
pub type BeforeHook = Fn(&mut Context, &Message, &str) -> bool + 'static;
diff --git a/src/framework/configuration.rs b/src/framework/configuration.rs
index 2854d90..bd64cba 100644
--- a/src/framework/configuration.rs
+++ b/src/framework/configuration.rs
@@ -269,8 +269,8 @@ impl Configuration {
if let Ok(current_user) = http::get_current_user() {
self.on_mention = Some(vec![
- format!("<@{}>", current_user.id), // Regular mention
- format!("<@!{}>", current_user.id), // Nickname mention
+ format!("<@{}>", current_user.id), // Regular mention
+ format!("<@!{}>", current_user.id) /* Nickname mention */,
]);
}
@@ -415,7 +415,9 @@ impl Configuration {
/// ```
pub fn delimiters(mut self, delimiters: Vec<&str>) -> Self {
self.delimiters.clear();
- self.delimiters.extend(delimiters.into_iter().map(|s| s.to_string()));
+ self.delimiters.extend(
+ delimiters.into_iter().map(|s| s.to_string()),
+ );
self
}
diff --git a/src/framework/create_command.rs b/src/framework/create_command.rs
index 242c62f..3110a9c 100644
--- a/src/framework/create_command.rs
+++ b/src/framework/create_command.rs
@@ -11,7 +11,9 @@ pub struct CreateCommand(pub Command);
impl CreateCommand {
/// Adds multiple aliases.
pub fn batch_known_as(mut self, names: Vec<&str>) -> Self {
- self.0.aliases.extend(names.into_iter().map(|n| n.to_owned()));
+ self.0.aliases.extend(
+ names.into_iter().map(|n| n.to_owned()),
+ );
self
}
@@ -50,20 +52,25 @@ impl CreateCommand {
/// .desc("Replies to a ping with a pong")
/// .exec(ping)));
///
- /// fn ping(_context: &mut Context, message: &Message, _args: Vec<String>, _original_msg: String) -> Result<(),
+ /// fn ping(_context: &mut Context, message: &Message, _args: Vec<String>, _original_msg:
+ /// String) -> Result<(),
/// String> {
/// let _ = message.channel_id.say("Pong!");
///
/// Ok(())
/// }
///
- /// fn owner_check(_context: &mut Context, message: &Message, _: &[String], _: &Arc<Command>) -> bool {
+ /// fn owner_check(_context: &mut Context, message: &Message, _: &[String], _:
+ /// &Arc<Command>) -> bool {
/// // replace with your user ID
/// message.author.id == 7
/// }
/// ```
pub fn check<F>(mut self, check: F) -> Self
- where F: Fn(&mut Context, &Message, &[String], &Arc<Command>) -> bool + Send + Sync + 'static {
+ where F: Fn(&mut Context, &Message, &[String], &Arc<Command>) -> bool
+ + Send
+ + Sync
+ + 'static {
self.0.checks.push(Box::new(check));
self
@@ -112,7 +119,10 @@ impl CreateCommand {
///
/// You can return `Err(string)` if there's an error.
pub fn exec_help<F>(mut self, f: F) -> Self
- where F: Fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, &[String])
+ where F: Fn(&mut Context,
+ &Message,
+ HashMap<String, Arc<CommandGroup>>,
+ &[String])
-> Result<(), String>
+ 'static {
self.0.exec = CommandType::WithCommands(Box::new(f));
diff --git a/src/framework/create_group.rs b/src/framework/create_group.rs
index a999268..b45c41e 100644
--- a/src/framework/create_group.rs
+++ b/src/framework/create_group.rs
@@ -34,7 +34,9 @@ impl CreateGroup {
if let Some(ref prefix) = self.0.prefix {
self.0.commands.insert(
format!("{} {}", prefix, n.to_owned()),
- CommandOrAlias::Alias(format!("{} {}", prefix, command_name.to_string())),
+ CommandOrAlias::Alias(
+ format!("{} {}", prefix, command_name.to_string()),
+ ),
);
} else {
self.0.commands.insert(
@@ -61,9 +63,10 @@ impl CreateGroup {
+ 'static {
let cmd = Arc::new(Command::new(f));
- self.0
- .commands
- .insert(command_name.to_owned(), CommandOrAlias::Command(cmd));
+ self.0.commands.insert(
+ command_name.to_owned(),
+ CommandOrAlias::Command(cmd),
+ );
self
}
diff --git a/src/framework/help_commands.rs b/src/framework/help_commands.rs
index dec0053..7846259 100644
--- a/src/framework/help_commands.rs
+++ b/src/framework/help_commands.rs
@@ -117,15 +117,19 @@ pub fn with_embeds(_: &mut Context,
if let Some(ref usage) = command.usage {
embed = embed.field(|f| {
- f.name("Usage")
- .value(&format!("`{} {}`", command_name, usage))
+ f.name("Usage").value(
+ &format!("`{} {}`", command_name, usage),
+ )
});
}
if let Some(ref example) = command.example {
embed = embed.field(|f| {
- f.name("Sample usage")
- .value(&format!("`{} {}`", command_name, example))
+ f.name("Sample usage").value(&format!(
+ "`{} {}`",
+ command_name,
+ example
+ ))
});
}
@@ -295,8 +299,10 @@ pub fn plain(_: &mut Context,
}
}
- let _ = msg.channel_id
- .say(&format!("**Error**: Command `{}` not found.", name));
+ let _ = msg.channel_id.say(&format!(
+ "**Error**: Command `{}` not found.",
+ name
+ ));
return Ok(());
}
diff --git a/src/framework/mod.rs b/src/framework/mod.rs
index c95c160..a3a9447 100644
--- a/src/framework/mod.rs
+++ b/src/framework/mod.rs
@@ -491,9 +491,12 @@ impl BuiltinFramework {
}
if let Some(guild) = guild_id.find() {
- return self.configuration
- .blocked_users
- .contains(&guild.read().unwrap().owner_id);
+ return self.configuration.blocked_users.contains(
+ &guild
+ .read()
+ .unwrap()
+ .owner_id,
+ );
}
}
@@ -504,10 +507,10 @@ impl BuiltinFramework {
fn has_correct_permissions(&self, command: &Arc<Command>, message: &Message) -> bool {
if !command.required_permissions.is_empty() {
if let Some(guild) = message.guild() {
- let perms = guild
- .read()
- .unwrap()
- .permissions_for(message.channel_id, message.author.id);
+ let perms = guild.read().unwrap().permissions_for(
+ message.channel_id,
+ message.author.id,
+ );
return perms.contains(command.required_permissions);
}
@@ -537,7 +540,8 @@ impl BuiltinFramework {
let rate_limit = bucket.take(message.author.id.0);
match bucket.check {
Some(ref check) => {
- let apply = feature_cache! {{
+ let apply =
+ feature_cache! {{
let guild_id = message.guild_id();
(check)(context, guild_id, message.channel_id, message.author.id)
} else {
@@ -548,8 +552,10 @@ impl BuiltinFramework {
return Some(DispatchError::RateLimited(rate_limit));
}
},
- None => if rate_limit > 0i64 {
- return Some(DispatchError::RateLimited(rate_limit));
+ None => {
+ if rate_limit > 0i64 {
+ return Some(DispatchError::RateLimited(rate_limit));
+ }
},
}
}
@@ -588,7 +594,7 @@ impl BuiltinFramework {
}
if (!self.configuration.allow_dm && message.is_private()) ||
- (command.guild_only && message.is_private()) {
+ (command.guild_only && message.is_private()) {
return Some(DispatchError::OnlyForGuilds);
}
@@ -599,14 +605,13 @@ impl BuiltinFramework {
if command.owners_only {
Some(DispatchError::OnlyForOwners)
- } else if !command
- .checks
- .iter()
- .all(|check| (check)(&mut context, message, args, command)) {
+ } else if !command.checks.iter().all(|check| {
+ (check)(&mut context, message, args, command)
+ }) {
Some(DispatchError::CheckFailed(command.to_owned()))
- } else if self.configuration
- .blocked_users
- .contains(&message.author.id) {
+ } else if self.configuration.blocked_users.contains(
+ &message.author.id,
+ ) {
Some(DispatchError::BlockedUser)
} else if self.configuration.disabled_commands.contains(to_check) {
Some(DispatchError::CommandDisabled(to_check.to_owned()))
@@ -661,16 +666,21 @@ impl BuiltinFramework {
where F: Fn(&mut Context, &Message, Vec<String>, String) -> Result<(), String> + 'static,
S: Into<String> {
{
- let ungrouped = self.groups
- .entry("Ungrouped".to_owned())
- .or_insert_with(|| Arc::new(CommandGroup::default()));
+ let ungrouped = self.groups.entry("Ungrouped".to_owned()).or_insert_with(
+ || {
+ Arc::new(CommandGroup::default())
+ },
+ );
if let Some(ref mut group) = Arc::get_mut(ungrouped) {
let name = command_name.into();
- group
- .commands
- .insert(name, CommandOrAlias::Command(Arc::new(Command::new(f))));
+ group.commands.insert(
+ name,
+ CommandOrAlias::Command(
+ Arc::new(Command::new(f)),
+ ),
+ );
}
}
@@ -693,9 +703,11 @@ impl BuiltinFramework {
pub fn command<F, S>(mut self, command_name: S, f: F) -> Self
where F: FnOnce(CreateCommand) -> CreateCommand, S: Into<String> {
{
- let ungrouped = self.groups
- .entry("Ungrouped".to_owned())
- .or_insert_with(|| Arc::new(CommandGroup::default()));
+ let ungrouped = self.groups.entry("Ungrouped".to_owned()).or_insert_with(
+ || {
+ Arc::new(CommandGroup::default())
+ },
+ );
if let Some(ref mut group) = Arc::get_mut(ungrouped) {
let cmd = f(CreateCommand(Command::default())).0;
@@ -710,15 +722,17 @@ impl BuiltinFramework {
}
} else {
for v in &cmd.aliases {
- group
- .commands
- .insert(v.to_owned(), CommandOrAlias::Alias(name.clone()));
+ group.commands.insert(
+ v.to_owned(),
+ CommandOrAlias::Alias(name.clone()),
+ );
}
}
- group
- .commands
- .insert(name, CommandOrAlias::Command(Arc::new(cmd)));
+ group.commands.insert(
+ name,
+ CommandOrAlias::Command(Arc::new(cmd)),
+ );
}
}
@@ -930,7 +944,7 @@ impl Framework for BuiltinFramework {
let command_length = built.len();
if let Some(&CommandOrAlias::Alias(ref points_to)) =
- group.commands.get(&built) {
+ group.commands.get(&built) {
built = points_to.to_owned();
}
@@ -945,7 +959,7 @@ impl Framework for BuiltinFramework {
};
if let Some(&CommandOrAlias::Command(ref command)) =
- group.commands.get(&to_check) {
+ group.commands.get(&to_check) {
let before = self.before.clone();
let command = command.clone();
let after = self.after.clone();
@@ -959,14 +973,24 @@ impl Framework for BuiltinFramework {
(utils::parse_quotes(content), content.to_string())
} else {
let delimiters = &self.configuration.delimiters;
- let regular_expression = delimiters.iter()
- .map(|delimiter| escape(delimiter)).join("|");
+ let regular_expression = delimiters
+ .iter()
+ .map(|delimiter| escape(delimiter))
+ .join("|");
let regex = Regex::new(&regular_expression).unwrap();
- (regex.split(content)
- .filter_map(|p| if !p.is_empty() { Some(p.to_string()) } else { None })
- .collect::<Vec<_>>(), content.to_string())
+ (
+ regex
+ .split(content)
+ .filter_map(|p| if !p.is_empty() {
+ Some(p.to_string())
+ } else {
+ None
+ })
+ .collect::<Vec<_>>(),
+ content.to_string(),
+ )
}
};
@@ -997,7 +1021,9 @@ impl Framework for BuiltinFramework {
Ok(())
},
- CommandType::Basic(ref x) => (x)(&mut context, &message, args, content),
+ CommandType::Basic(ref x) => {
+ (x)(&mut context, &message, args, content)
+ },
CommandType::WithCommands(ref x) => {
(x)(&mut context, &message, groups, &args)
},