aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authorLakelezz <[email protected]>2018-03-15 23:03:56 +0100
committeralex <[email protected]>2018-03-15 23:03:56 +0100
commit02dc5064d9402f73ef514c9b8ffa318f5d4235ff (patch)
tree696b9746abfb532d689ccaadfecea2aefe53d7c9 /src/framework
parentAdd a basic CONTRIBUTING.md (diff)
downloadserenity-02dc5064d9402f73ef514c9b8ffa318f5d4235ff.tar.xz
serenity-02dc5064d9402f73ef514c9b8ffa318f5d4235ff.zip
Fix no-cache standardframework compilation (#290)
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/create_command.rs11
-rw-r--r--src/framework/standard/create_group.rs1
-rw-r--r--src/framework/standard/help_commands.rs4
-rw-r--r--src/framework/standard/mod.rs24
4 files changed, 24 insertions, 16 deletions
diff --git a/src/framework/standard/create_command.rs b/src/framework/standard/create_command.rs
index 672a955..8fbb975 100644
--- a/src/framework/standard/create_command.rs
+++ b/src/framework/standard/create_command.rs
@@ -218,6 +218,7 @@ impl CreateCommand {
}
/// Sets roles that are allowed to use the command.
+ #[cfg(feature="cache")]
pub fn allowed_roles<T: ToString, It: IntoIterator<Item=T>>(mut self, allowed_roles: It) -> Self {
self.0.allowed_roles = allowed_roles.into_iter().map(|x| x.to_string()).collect();
@@ -225,7 +226,7 @@ impl CreateCommand {
}
/// Sets an initialise middleware to be called upon the command's actual registration.
- ///
+ ///
/// This is similiar to implementing the `init` function on `Command`.
pub fn init<F: Fn() + Send + Sync + 'static>(mut self, f: F) -> Self {
self.2.init = Some(Arc::new(f));
@@ -234,9 +235,9 @@ impl CreateCommand {
}
/// Sets a before middleware to be called before the command's execution.
- ///
+ ///
/// This is similiar to implementing the `before` function on `Command`.
- pub fn before<F: Send + Sync + 'static>(mut self, f: F) -> Self
+ pub fn before<F: Send + Sync + 'static>(mut self, f: F) -> Self
where F: Fn(&mut Context, &Message) -> bool {
self.2.before = Some(Arc::new(f));
@@ -244,9 +245,9 @@ impl CreateCommand {
}
/// Sets an after middleware to be called after the command's execution.
- ///
+ ///
/// This is similiar to implementing the `after` function on `Command`.
- pub fn after<F: Send + Sync + 'static>(mut self, f: F) -> Self
+ pub fn after<F: Send + Sync + 'static>(mut self, f: F) -> Self
where F: Fn(&mut Context, &Message, &Result<(), CommandError>) {
self.2.after = Some(Arc::new(f));
diff --git a/src/framework/standard/create_group.rs b/src/framework/standard/create_group.rs
index df3d97f..c33f67a 100644
--- a/src/framework/standard/create_group.rs
+++ b/src/framework/standard/create_group.rs
@@ -148,6 +148,7 @@ impl CreateGroup {
}
/// Sets roles that are allowed to use the command.
+ #[cfg(feature = "cache")]
pub fn allowed_roles<T: ToString, It: IntoIterator<Item=T>>(mut self, allowed_roles: It) -> Self {
self.0.allowed_roles = allowed_roles.into_iter().map(|x| x.to_string()).collect();
diff --git a/src/framework/standard/help_commands.rs b/src/framework/standard/help_commands.rs
index d740086..0a76636 100644
--- a/src/framework/standard/help_commands.rs
+++ b/src/framework/standard/help_commands.rs
@@ -24,6 +24,7 @@
//! [`with_embeds`]: fn.with_embeds.html
use client::Context;
+#[cfg(feature = "cache")]
use framework::standard::{has_correct_roles, has_correct_permissions};
use model::channel::Message;
use model::id::ChannelId;
@@ -55,6 +56,7 @@ fn remove_aliases(cmds: &HashMap<String, CommandOrAlias>) -> HashMap<&String, &I
/// Checks whether a user is member of required roles
/// and given the required permissions.
+#[cfg(feature = "cache")]
pub fn has_all_requirements(cmd: &Arc<CommandOptions>, msg: &Message) -> bool {
if let Some(guild) = msg.guild() {
let guild = guild.read();
@@ -92,6 +94,7 @@ pub fn has_all_requirements(cmd: &Arc<CommandOptions>, msg: &Message) -> bool {
/// client.with_framework(StandardFramework::new()
/// .help(help_commands::with_embeds));
/// ```
+#[cfg(feature = "cache")]
pub fn with_embeds<H: BuildHasher>(
_: &mut Context,
msg: &Message,
@@ -335,6 +338,7 @@ pub fn with_embeds<H: BuildHasher>(
/// client.with_framework(StandardFramework::new()
/// .help(help_commands::plain));
/// ```
+#[cfg(feature = "cache")]
pub fn plain<H: BuildHasher>(
_: &mut Context,
msg: &Message,
diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs
index 0593911..83b284d 100644
--- a/src/framework/standard/mod.rs
+++ b/src/framework/standard/mod.rs
@@ -567,15 +567,19 @@ impl StandardFramework {
} else if self.configuration.disabled_commands.contains(built) {
Some(DispatchError::CommandDisabled(built.to_string()))
} else {
- if !command.allowed_roles.is_empty() {
- if let Some(guild) = message.guild() {
- let guild = guild.read();
-
- if let Some(member) = guild.members.get(&message.author.id) {
- if let Ok(permissions) = member.permissions() {
- if !permissions.administrator()
- && !has_correct_roles(command, &guild, member) {
- return Some(DispatchError::LackingRole);
+
+ #[cfg(feature = "cache")] {
+ if !command.allowed_roles.is_empty() {
+ if let Some(guild) = message.guild() {
+ let guild = guild.read();
+
+ if let Some(member) = guild.members.get(&message.author.id) {
+ if let Ok(permissions) = member.permissions() {
+
+ if !permissions.administrator()
+ && !has_correct_roles(command, &guild, member) {
+ return Some(DispatchError::LackingRole);
+ }
}
}
}
@@ -1091,7 +1095,6 @@ impl Framework for StandardFramework {
self.user_id = user_id.0;
}
}
-
#[cfg(feature = "cache")]
pub fn has_correct_permissions(command: &Arc<CommandOptions>, message: &Message) -> bool {
if !command.required_permissions.is_empty() {
@@ -1106,7 +1109,6 @@ pub fn has_correct_permissions(command: &Arc<CommandOptions>, message: &Message)
true
}
-#[cfg(feature = "cache")]
pub fn has_correct_roles(cmd: &Arc<CommandOptions>, guild: &Guild, member: &Member) -> bool {
if cmd.allowed_roles.is_empty() {
true