diff options
| author | Zeyla Hellyer <[email protected]> | 2017-09-18 17:48:52 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-09-18 17:48:52 -0700 |
| commit | dae2cb77b407044f44a7a2790d93efba3891854e (patch) | |
| tree | bef263c4490536cf8b56e988e71dd1aa43bc2696 /src/framework | |
| parent | Fix compiles of a variety of feature combinations (diff) | |
| download | serenity-dae2cb77b407044f44a7a2790d93efba3891854e.tar.xz serenity-dae2cb77b407044f44a7a2790d93efba3891854e.zip | |
Apply rustfmt
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/standard/args.rs | 7 | ||||
| -rw-r--r-- | src/framework/standard/buckets.rs | 6 | ||||
| -rw-r--r-- | src/framework/standard/command.rs | 5 | ||||
| -rw-r--r-- | src/framework/standard/configuration.rs | 51 | ||||
| -rw-r--r-- | src/framework/standard/create_command.rs | 11 | ||||
| -rw-r--r-- | src/framework/standard/create_group.rs | 11 | ||||
| -rw-r--r-- | src/framework/standard/help_commands.rs | 18 | ||||
| -rw-r--r-- | src/framework/standard/mod.rs | 77 |
8 files changed, 73 insertions, 113 deletions
diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs index b88f345..d22b1a8 100644 --- a/src/framework/standard/args.rs +++ b/src/framework/standard/args.rs @@ -144,9 +144,10 @@ impl Args { return Err(Error::Eos); } - match self.delimiter_split.iter().position( - |e| e.parse::<T>().is_ok(), - ) { + match self.delimiter_split + .iter() + .position(|e| e.parse::<T>().is_ok()) + { Some(index) => { let value = self.delimiter_split .get(index) diff --git a/src/framework/standard/buckets.rs b/src/framework/standard/buckets.rs index f2c4486..4719b85 100644 --- a/src/framework/standard/buckets.rs +++ b/src/framework/standard/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/standard/command.rs b/src/framework/standard/command.rs index 501798c..e9bdd52 100644 --- a/src/framework/standard/command.rs +++ b/src/framework/standard/command.rs @@ -6,10 +6,7 @@ use std::collections::HashMap; pub type Check = Fn(&mut Context, &Message, &mut Args, &Arc<Command>) -> bool + 'static; pub type Exec = Fn(&mut Context, &Message, Args) -> Result<(), String> + 'static; -pub type Help = Fn(&mut Context, - &Message, - HashMap<String, Arc<CommandGroup>>, - Args) +pub type Help = Fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, Args) -> Result<(), String> + 'static; pub type BeforeHook = Fn(&mut Context, &Message, &str) -> bool + 'static; diff --git a/src/framework/standard/configuration.rs b/src/framework/standard/configuration.rs index 015fb42..58861bb 100644 --- a/src/framework/standard/configuration.rs +++ b/src/framework/standard/configuration.rs @@ -33,34 +33,20 @@ use model::{GuildId, Message, UserId}; /// [`Client`]: ../../client/struct.Client.html /// [`Framework`]: struct.Framework.html pub struct Configuration { - #[doc(hidden)] - pub allow_dm: bool, - #[doc(hidden)] - pub allow_whitespace: bool, - #[doc(hidden)] - pub blocked_guilds: HashSet<GuildId>, - #[doc(hidden)] - pub blocked_users: HashSet<UserId>, - #[doc(hidden)] - pub depth: usize, - #[doc(hidden)] - pub disabled_commands: HashSet<String>, - #[doc(hidden)] - pub dynamic_prefix: Option<Box<PrefixCheck>>, - #[doc(hidden)] - pub ignore_bots: bool, - #[doc(hidden)] - pub ignore_webhooks: bool, - #[doc(hidden)] - pub on_mention: Option<Vec<String>>, - #[doc(hidden)] - pub owners: HashSet<UserId>, - #[doc(hidden)] - pub prefixes: Vec<String>, - #[doc(hidden)] - pub delimiters: Vec<String>, - #[doc(hidden)] - pub case_insensitive: bool, + #[doc(hidden)] pub allow_dm: bool, + #[doc(hidden)] pub allow_whitespace: bool, + #[doc(hidden)] pub blocked_guilds: HashSet<GuildId>, + #[doc(hidden)] pub blocked_users: HashSet<UserId>, + #[doc(hidden)] pub depth: usize, + #[doc(hidden)] pub disabled_commands: HashSet<String>, + #[doc(hidden)] pub dynamic_prefix: Option<Box<PrefixCheck>>, + #[doc(hidden)] pub ignore_bots: bool, + #[doc(hidden)] pub ignore_webhooks: bool, + #[doc(hidden)] pub on_mention: Option<Vec<String>>, + #[doc(hidden)] pub owners: HashSet<UserId>, + #[doc(hidden)] pub prefixes: Vec<String>, + #[doc(hidden)] pub delimiters: Vec<String>, + #[doc(hidden)] pub case_insensitive: bool, } impl Configuration { @@ -271,8 +257,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 ]); } @@ -417,9 +403,8 @@ 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/standard/create_command.rs b/src/framework/standard/create_command.rs index 546447e..a8421e6 100644 --- a/src/framework/standard/create_command.rs +++ b/src/framework/standard/create_command.rs @@ -11,9 +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 } @@ -115,10 +115,7 @@ 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>>, - Args) + where F: Fn(&mut Context, &Message, HashMap<String, Arc<CommandGroup>>, Args) -> Result<(), String> + 'static { self.0.exec = CommandType::WithCommands(Box::new(f)); diff --git a/src/framework/standard/create_group.rs b/src/framework/standard/create_group.rs index 2184c93..d4e2d15 100644 --- a/src/framework/standard/create_group.rs +++ b/src/framework/standard/create_group.rs @@ -51,9 +51,7 @@ 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( @@ -77,10 +75,9 @@ impl CreateGroup { where F: Fn(&mut Context, &Message, Args) -> Result<(), String> + Send + Sync + '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/standard/help_commands.rs b/src/framework/standard/help_commands.rs index 72e0468..a14f510 100644 --- a/src/framework/standard/help_commands.rs +++ b/src/framework/standard/help_commands.rs @@ -140,19 +140,15 @@ 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)) }); } @@ -342,10 +338,8 @@ 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/standard/mod.rs b/src/framework/standard/mod.rs index bd1300d..4e145e0 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -404,9 +404,9 @@ impl StandardFramework { } if let Some(guild) = guild_id.find() { - return self.configuration.blocked_users.contains( - &guild.with(|g| g.owner_id), - ); + return self.configuration + .blocked_users + .contains(&guild.with(|g| g.owner_id)); } } @@ -417,9 +417,8 @@ impl StandardFramework { 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.with(|g| { - g.permissions_for(message.channel_id, message.author.id) - }); + let perms = guild + .with(|g| g.permissions_for(message.channel_id, message.author.id)); return perms.contains(command.required_permissions); } @@ -449,8 +448,7 @@ impl StandardFramework { 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 { @@ -461,10 +459,8 @@ impl StandardFramework { 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)); }, } } @@ -514,9 +510,9 @@ impl StandardFramework { if command.owners_only { Some(DispatchError::OnlyForOwners) - } 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())) @@ -543,9 +539,10 @@ impl StandardFramework { } } - let all_passed = command.checks.iter().all(|check| { - check(&mut context, message, args, command) - }); + let all_passed = command + .checks + .iter() + .all(|check| check(&mut context, message, args, command)); if all_passed { None @@ -599,21 +596,16 @@ 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> { { - 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)))); } } @@ -636,11 +628,9 @@ impl StandardFramework { 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; @@ -655,17 +645,15 @@ impl StandardFramework { } } 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))); } } @@ -878,8 +866,9 @@ impl Framework for StandardFramework { for group in groups.values() { let command_length = built.len(); - if let Some(&CommandOrAlias::Alias(ref points_to)) = - group.commands.get(&built) { + let cmd = group.commands.get(&built); + + if let Some(&CommandOrAlias::Alias(ref points_to)) = cmd { built = points_to.to_owned(); } |