aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-12-10 10:16:35 -0800
committerAustin Hellyer <[email protected]>2016-12-10 10:16:35 -0800
commit530de25aa5345223fa924e76eb69bb32e484a62a (patch)
treea243a073855f4a8fdc57e122dc52538be76e9414 /src/model
parentDeprecate embed image/thumbnail height/width (diff)
downloadserenity-530de25aa5345223fa924e76eb69bb32e484a62a.tar.xz
serenity-530de25aa5345223fa924e76eb69bb32e484a62a.zip
Fix no-cache+method conditional compiles
Additionally, flag imports behind feature flags to avoid unused imports.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel.rs9
-rw-r--r--src/model/guild.rs11
-rw-r--r--src/model/invite.rs9
-rw-r--r--src/model/misc.rs6
-rw-r--r--src/model/user.rs21
-rw-r--r--src/model/utils.rs6
6 files changed, 35 insertions, 27 deletions
diff --git a/src/model/channel.rs b/src/model/channel.rs
index 4ba31d6..75dfc54 100644
--- a/src/model/channel.rs
+++ b/src/model/channel.rs
@@ -24,7 +24,7 @@ use std::io::{Read, Write as IoWrite};
use std::mem;
#[cfg(feature = "methods")]
use std::path::{Path, PathBuf};
-#[cfg(feature = "methods")]
+#[cfg(all(feature="cache", feature = "methods"))]
use super::utils;
#[cfg(feature = "methods")]
@@ -894,9 +894,9 @@ impl GuildChannel {
/// Deletes this channel, returning the channel on a successful deletion.
#[cfg(feature = "methods")]
pub fn delete(&self) -> Result<Channel> {
- let req = permissions::MANAGE_CHANNELS;
-
feature_cache_enabled! {{
+ let req = permissions::MANAGE_CHANNELS;
+
if !utils::user_has_perms(self.id, req)? {
return Err(Error::Client(ClientError::InvalidPermissions(req)));
}
@@ -921,9 +921,10 @@ impl GuildChannel {
#[cfg(feature = "methods")]
pub fn edit<F>(&mut self, f: F) -> Result<()>
where F: FnOnce(EditChannel) -> EditChannel {
- let req = permissions::MANAGE_CHANNELS;
feature_cache_enabled! {{
+ let req = permissions::MANAGE_CHANNELS;
+
if !utils::user_has_perms(self.id, req)? {
return Err(Error::Client(ClientError::InvalidPermissions(req)));
}
diff --git a/src/model/guild.rs b/src/model/guild.rs
index d0627eb..0c7bb57 100644
--- a/src/model/guild.rs
+++ b/src/model/guild.rs
@@ -18,10 +18,12 @@ use ::utils::decode_array;
#[cfg(feature = "methods")]
use serde_json::builder::ObjectBuilder;
-#[cfg(feature = "methods")]
+#[cfg(all(feature="cache", feature = "methods"))]
use std::mem;
#[cfg(feature = "methods")]
-use ::utils::builder::{EditGuild, EditMember, EditRole};
+use ::utils::builder::{EditGuild, EditRole};
+#[cfg(all(feature="cache", feature="methods"))]
+use ::utils::builder::EditMember;
#[cfg(feature = "methods")]
use ::client::rest;
@@ -180,11 +182,6 @@ impl Guild {
Ok(permissions.is_empty())
}
- #[cfg(not(feature = "cache"))]
- fn has_perms(&self, mut permissions: Permissions) -> Result<bool> {
- Ok(true)
- }
-
/// Ban a [`User`] from the guild. All messages by the
/// user within the last given number of days given will be deleted. This
/// may be a range between `0` and `7`.
diff --git a/src/model/invite.rs b/src/model/invite.rs
index 64fa44d..804f5ef 100644
--- a/src/model/invite.rs
+++ b/src/model/invite.rs
@@ -1,8 +1,11 @@
use super::{Invite, RichInvite};
use ::client::rest;
use ::internal::prelude::*;
-use super::{permissions, utils};
+#[cfg(feature="cache")]
+use super::permissions;
+#[cfg(all(feature="cache", feature="methods"))]
+use super::utils;
#[cfg(feature = "cache")]
use ::client::CACHE;
@@ -114,9 +117,9 @@ impl RichInvite {
/// [permission]: permissions/index.html
#[cfg(feature = "methods")]
pub fn delete(&self) -> Result<Invite> {
- let req = permissions::MANAGE_GUILD;
-
feature_cache_enabled! {{
+ let req = permissions::MANAGE_GUILD;
+
if !utils::user_has_perms(self.channel.id, req)? {
return Err(Error::Client(ClientError::InvalidPermissions(req)));
}
diff --git a/src/model/misc.rs b/src/model/misc.rs
index 263362f..0a07738 100644
--- a/src/model/misc.rs
+++ b/src/model/misc.rs
@@ -78,7 +78,7 @@ impl Mentionable for User {
}
}
-#[cfg(feature = "cache")]
+#[cfg(all(feature="cache", feature="methods"))]
impl FromStr for User {
type Err = ();
fn from_str(s: &str) -> StdResult<Self, ()> {
@@ -101,7 +101,7 @@ impl FromStr for UserId {
}
}
-#[cfg(feature = "cache")]
+#[cfg(all(feature="cache", feature="methods"))]
impl FromStr for Role {
type Err = ();
fn from_str(s: &str) -> StdResult<Self, ()> {
@@ -138,7 +138,7 @@ impl FromStr for ChannelId {
}
}
-#[cfg(feature = "cache")]
+#[cfg(all(feature="cache", feature="methods"))]
impl FromStr for Channel {
type Err = ();
fn from_str(s: &str) -> StdResult<Self, ()> {
diff --git a/src/model/user.rs b/src/model/user.rs
index f5906ab..adc766f 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -1,29 +1,32 @@
-use std::{fmt, mem};
+use std::fmt;
use super::utils::{into_map, into_string, remove};
use super::{
CurrentUser,
FriendSourceFlags,
GuildContainer,
GuildId,
- GuildInfo,
RoleId,
UserSettings,
User,
};
-use ::client::rest::GuildPagination;
use ::internal::prelude::*;
-use ::utils::builder::EditProfile;
use ::utils::decode_array;
use ::model::misc::Mentionable;
#[cfg(feature = "methods")]
use serde_json::builder::ObjectBuilder;
+#[cfg(feature="methods")]
+use std::mem;
#[cfg(feature = "methods")]
use super::Message;
#[cfg(feature = "methods")]
use time::Timespec;
#[cfg(feature = "methods")]
-use ::client::rest;
+use ::client::rest::{self, GuildPagination};
+#[cfg(feature="methods")]
+use super::GuildInfo;
+#[cfg(feature="methods")]
+use ::utils::builder::EditProfile;
#[cfg(feature = "cache")]
use ::client::CACHE;
@@ -45,7 +48,7 @@ impl CurrentUser {
///
/// Change the avatar:
///
- /// ```rust,no_run
+ /// ```rust,ignore
/// use serenity::client::CACHE;
///
/// let avatar = serenity::utils::read_image("./avatar.png").unwrap();
@@ -79,12 +82,14 @@ impl CurrentUser {
}
}
- /// Returns the DiscordTag(tm) of a User.
+ /// Returns the DiscordTag™ of a User.
+ #[cfg(feature="methods")]
pub fn distinct(&self) -> String {
format!("{}#{}", self.name, self.discriminator)
}
/// Gets a list of guilds that the current user is in.
+ #[cfg(feature="methods")]
pub fn guilds(&self) -> Result<Vec<GuildInfo>> {
rest::get_guilds(GuildPagination::After(GuildId(0)), 100)
}
@@ -178,6 +183,8 @@ impl User {
/// [`GuildId`]: struct.GuildId.html
/// [`Role`]: struct.Role.html
/// [`Cache`]: ../ext/cache/struct.Cache.html
+ #[allow(unused_variables)]
+ // no-cache would warn on guild_id.
pub fn has_role<G, R>(&self, guild: G, role: R) -> bool
where G: Into<GuildContainer>, R: Into<RoleId> {
let role_id = role.into();
diff --git a/src/model/utils.rs b/src/model/utils.rs
index 2668142..e4b2445 100644
--- a/src/model/utils.rs
+++ b/src/model/utils.rs
@@ -17,11 +17,11 @@ use super::{
use ::internal::prelude::*;
use ::utils::{decode_array, into_array};
-#[cfg(feature = "methods")]
+#[cfg(all(feature="cache", feature="methods"))]
use super::permissions::{self, Permissions};
-#[cfg(all(feature = "cache", feature = "methods"))]
+#[cfg(all(feature="cache", feature="methods"))]
use ::client::CACHE;
-#[cfg(all(feature = "cache", feature = "methods"))]
+#[cfg(all(feature="cache", feature="methods"))]
use ::ext::cache::ChannelRef;
#[macro_escape]