aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-15 11:36:53 -0800
committerAustin Hellyer <[email protected]>2016-11-15 11:36:53 -0800
commit5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4 (patch)
tree7cf531e4790109d6d7edd26bc5b483378d5ba5ac /src/model
parentEmbed Author: everything but 'name' is optional (diff)
downloadserenity-5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4.tar.xz
serenity-5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4.zip
Add state/framework/etc. conditional compile flags
This adds conditional compilation for the following features, in addition to the voice conditional compilation flag: - extras (message builder) - framework - methods - state These 4 are enabled _by default_, while the `voice` feature flag is disabled. Disabling the state will allow incredibly low-memory bots.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel.rs68
-rw-r--r--src/model/gateway.rs4
-rw-r--r--src/model/guild.rs51
-rw-r--r--src/model/id.rs11
-rw-r--r--src/model/invite.rs4
-rw-r--r--src/model/misc.rs1
-rw-r--r--src/model/mod.rs10
-rw-r--r--src/model/permissions.rs3
-rw-r--r--src/model/user.rs25
-rw-r--r--src/model/utils.rs8
-rw-r--r--src/model/webhook.rs4
11 files changed, 165 insertions, 24 deletions
diff --git a/src/model/channel.rs b/src/model/channel.rs
index 429fa01..72a1f09 100644
--- a/src/model/channel.rs
+++ b/src/model/channel.rs
@@ -1,11 +1,5 @@
-use hyper::Client as HyperClient;
-use serde_json::builder::ObjectBuilder;
use std::borrow::Cow;
use std::fmt::{self, Write};
-use std::fs::File;
-use std::io::{Read, Write as IoWrite};
-use std::mem;
-use std::path::{Path, PathBuf};
use super::utils::{
decode_id,
into_map,
@@ -15,16 +9,34 @@ use super::utils::{
warn_field,
};
use super::*;
-use super::utils;
-use ::utils::builder::{CreateEmbed, CreateInvite, EditChannel};
-use ::client::{STATE, http};
use ::constants;
use ::internal::prelude::*;
use ::utils::decode_array;
+#[cfg(feature = "methods")]
+use hyper::Client as HyperClient;
+#[cfg(feature = "methods")]
+use serde_json::builder::ObjectBuilder;
+#[cfg(feature = "methods")]
+use std::fs::File;
+#[cfg(feature = "methods")]
+use std::io::{Read, Write as IoWrite};
+#[cfg(feature = "methods")]
+use std::mem;
+#[cfg(feature = "methods")]
+use std::path::{Path, PathBuf};
+#[cfg(feature = "methods")]
+use super::utils;
+
+#[cfg(feature = "methods")]
+use ::utils::builder::{CreateEmbed, CreateInvite, EditChannel};
+#[cfg(feature = "methods")]
+use ::client::{STATE, http};
+
impl Attachment {
/// If this attachment is an image, then a tuple of the width and height
/// in pixels is returned.
+ #[cfg(feature = "methods")]
pub fn dimensions(&self) -> Option<(u64, u64)> {
if let (Some(width), Some(height)) = (self.width, self.height) {
Some((width, height))
@@ -99,6 +111,7 @@ impl Attachment {
/// [`Error::Hyper`]: ../enum.Error.html#variant.Hyper
/// [`Error::Io`]: ../enum.Error.html#variant.Io
/// [`Message`]: struct.Message.html
+ #[cfg(feature = "methods")]
pub fn download(&self) -> Result<Vec<u8>> {
let hyper = HyperClient::new();
let mut response = try!(hyper.get(&self.url).send());
@@ -163,6 +176,7 @@ impl Attachment {
/// [`Error::Hyper`]: ../enum.Error.html#variant.Hyper
/// [`Error::Io`]: ../enum.Error.html#variant.Io
/// [`Message`]: struct.Message.html
+ #[cfg(feature = "methods")]
pub fn download_to_directory<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf> {
let bytes = try!(self.download());
@@ -196,6 +210,7 @@ impl Channel {
/// closest functionality is leaving it.
///
/// [`Group`]: struct.Group.html
+ #[cfg(feature = "methods")]
pub fn delete(&self) -> Result<()> {
match *self {
Channel::Group(ref group) => {
@@ -258,6 +273,7 @@ impl Embed {
/// This should only be useful in conjunction with [`Webhook::execute`].
///
/// [`Webhook::execute`]: struct.Webhook.html
+ #[cfg(feature = "methods")]
#[inline(always)]
pub fn fake<F>(f: F) -> Value where F: FnOnce(CreateEmbed) -> CreateEmbed {
f(CreateEmbed::default()).0.build()
@@ -270,6 +286,7 @@ impl Group {
///
/// **Note**: Groups have a limit of 10 recipients, including the current
/// user.
+ #[cfg(feature = "methods")]
pub fn add_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> {
let user = user.into();
@@ -282,6 +299,7 @@ impl Group {
}
/// Broadcasts that the current user is typing in the group.
+ #[cfg(feature = "methods")]
pub fn broadcast_typing(&self) -> Result<()> {
http::broadcast_typing(self.channel_id.0)
}
@@ -301,6 +319,7 @@ impl Group {
///
/// [`ClientError::DeleteMessageDaysAmount`]: ../client/enum.ClientError.html#variant.DeleteMessageDaysAmount
/// [`Context::delete_messages`]: ../client/struct.Context.html#delete_messages
+ #[cfg(feature = "methods")]
pub fn delete_messages(&self, message_ids: &[MessageId]) -> Result<()> {
if message_ids.len() < 2 || message_ids.len() > 100 {
return Err(Error::Client(ClientError::BulkDeleteAmount));
@@ -324,6 +343,7 @@ impl Group {
}
/// Leaves the group.
+ #[cfg(feature = "methods")]
pub fn leave(&self) -> Result<Group> {
http::leave_group(self.channel_id.0)
}
@@ -352,6 +372,7 @@ impl Group {
}
/// Retrieves the list of messages that have been pinned in the group.
+ #[cfg(feature = "methods")]
pub fn pins(&self) -> Result<Vec<Message>> {
http::get_pins(self.channel_id.0)
}
@@ -360,6 +381,7 @@ impl Group {
/// the group, then nothing is done.
///
/// **Note**: This is only available to the group owner.
+ #[cfg(feature = "methods")]
pub fn remove_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> {
let user = user.into();
@@ -378,6 +400,7 @@ impl Group {
/// **Note**: Requires the [Send Messages] permission.
///
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
+ #[cfg(feature = "methods")]
pub fn send_message(&self, content: &str) -> Result<Message> {
let map = ObjectBuilder::new()
.insert("content", content)
@@ -408,6 +431,7 @@ impl Message {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidUser
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
+ #[cfg(feature = "methods")]
pub fn delete(&self) -> Result<()> {
let req = permissions::MANAGE_MESSAGES;
let is_author = self.author.id != STATE.lock().unwrap().user.id;
@@ -435,6 +459,7 @@ impl Message {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`Reaction`]: struct.Reaction.html
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
+ #[cfg(feature = "methods")]
pub fn delete_reactions(&self) -> Result<()> {
let req = permissions::MANAGE_MESSAGES;
@@ -462,6 +487,7 @@ impl Message {
///
/// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidUser
/// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
+ #[cfg(feature = "methods")]
pub fn edit(&mut self, new_content: &str) -> Result<()> {
if let Some(length_over) = Message::overflow_length(new_content) {
return Err(Error::Client(ClientError::MessageTooLong(length_over)));
@@ -516,6 +542,7 @@ impl Message {
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
+ #[cfg(feature = "methods")]
pub fn pin(&self) -> Result<()> {
let req = permissions::MANAGE_MESSAGES;
@@ -539,6 +566,7 @@ impl Message {
/// [`Emoji`]: struct.Emoji.html
/// [Add Reactions]: permissions/constant.ADD_REACTIONS.html
/// [permissions]: permissions
+ #[cfg(feature = "methods")]
pub fn react<R: Into<ReactionType>>(&self, reaction_type: R) -> Result<()> {
let req = permissions::ADD_REACTIONS;
@@ -572,6 +600,7 @@ impl Message {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
+ #[cfg(feature = "methods")]
pub fn reply(&self, content: &str) -> Result<Message> {
if let Some(length_over) = Message::overflow_length(content) {
return Err(Error::Client(ClientError::MessageTooLong(length_over)));
@@ -609,6 +638,7 @@ impl Message {
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
+ #[cfg(feature = "methods")]
pub fn unpin(&self) -> Result<()> {
let req = permissions::MANAGE_MESSAGES;
@@ -621,6 +651,7 @@ impl Message {
}
impl PermissionOverwrite {
+ #[doc(hidden)]
pub fn decode(value: Value) -> Result<PermissionOverwrite> {
let mut map = try!(into_map(value));
let id = try!(remove(&mut map, "id").and_then(decode_id));
@@ -641,6 +672,7 @@ impl PermissionOverwrite {
impl PrivateChannel {
/// Broadcasts that the current user is typing to the recipient.
+ #[cfg(feature = "methods")]
pub fn broadcast_typing(&self) -> Result<()> {
http::broadcast_typing(self.id.0)
}
@@ -672,6 +704,7 @@ impl PrivateChannel {
/// [`ClientError::InvalidUser`] if the current user is not a bot user.
///
/// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidOperationAsUser
+ #[cfg(feature = "methods")]
pub fn delete_messages(&self, message_ids: &[MessageId]) -> Result<()> {
if !STATE.lock().unwrap().user.bot {
return Err(Error::Client(ClientError::InvalidOperationAsUser));
@@ -691,12 +724,14 @@ impl PrivateChannel {
/// Deletes the channel. This does not delete the contents of the channel,
/// and is equivilant to closing a private channel on the client, which can
/// be re-opened.
+ #[cfg(feature = "methods")]
pub fn delete(&self) -> Result<Channel> {
http::delete_channel(self.id.0)
}
/// Retrieves the list of messages that have been pinned in the private
/// channel.
+ #[cfg(feature = "methods")]
pub fn pins(&self) -> Result<Vec<Message>> {
http::get_pins(self.id.0)
}
@@ -712,6 +747,7 @@ impl PrivateChannel {
/// over the limit.
///
/// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
+ #[cfg(feature = "methods")]
pub fn send_message(&self, content: &str) -> Result<Message> {
if let Some(length_over) = Message::overflow_length(content) {
return Err(Error::Client(ClientError::MessageTooLong(length_over)));
@@ -749,10 +785,12 @@ impl PublicChannel {
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Send Messages]: permissions/constants.SEND_MESSAGES.html
+ #[cfg(feature = "methods")]
pub fn broadcast_typing(&self) -> Result<()> {
http::broadcast_typing(self.id.0)
}
+ #[cfg(feature = "methods")]
pub fn create_invite<F>(&self, f: F) -> Result<RichInvite>
where F: FnOnce(CreateInvite) -> CreateInvite {
let req = permissions::CREATE_INVITE;
@@ -766,6 +804,7 @@ impl PublicChannel {
http::create_invite(self.id.0, map)
}
+ #[doc(hidden)]
pub fn decode(value: Value) -> Result<PublicChannel> {
let mut map = try!(into_map(value));
@@ -774,6 +813,7 @@ impl PublicChannel {
PublicChannel::decode_guild(Value::Object(map), id)
}
+ #[doc(hidden)]
pub fn decode_guild(value: Value, guild_id: GuildId) -> Result<PublicChannel> {
let mut map = try!(into_map(value));
missing!(map, PublicChannel {
@@ -792,6 +832,7 @@ impl PublicChannel {
}
/// Deletes this channel, returning the channel on a successful deletion.
+ #[cfg(feature = "methods")]
pub fn delete(&self) -> Result<Channel> {
let req = permissions::MANAGE_CHANNELS;
@@ -801,8 +842,9 @@ impl PublicChannel {
http::delete_channel(self.id.0)
}
- pub fn edit<F>(&mut self, f: F) -> Result<()>
+ #[cfg(feature = "methods")]
+ pub fn edit<F>(&mut self, f: F) -> Result<()>
where F: FnOnce(EditChannel) -> EditChannel {
let req = permissions::MANAGE_CHANNELS;
@@ -834,6 +876,7 @@ impl PublicChannel {
self.id.mention()
}
+ #[cfg(feature = "methods")]
pub fn pins(&self) -> Result<Vec<Message>> {
http::get_pins(self.id.0)
}
@@ -856,6 +899,7 @@ impl PublicChannel {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
+ #[cfg(feature = "methods")]
pub fn send_message(&self, content: &str) -> Result<Message> {
if let Some(length_over) = Message::overflow_length(content) {
return Err(Error::Client(ClientError::MessageTooLong(length_over)));
@@ -881,6 +925,7 @@ impl PublicChannel {
/// **Note**: Requires the [Manage Webhooks] permission.
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[cfg(feature = "methods")]
pub fn webhooks(&self) -> Result<Vec<Webhook>> {
http::get_channel_webhooks(self.id.0)
}
@@ -908,6 +953,7 @@ impl Reaction {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
/// [permissions]: permissions
+ #[cfg(feature = "methods")]
pub fn delete(&self) -> Result<()> {
let user = if self.user_id == STATE.lock().unwrap().user.id {
None
@@ -958,6 +1004,7 @@ impl Reaction {
/// [`User`]: struct.User.html
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
/// [permissions]: permissions
+ #[cfg(feature = "methods")]
pub fn users<R, U>(&self,
reaction_type: R,
limit: Option<u8>,
@@ -1013,6 +1060,7 @@ impl ReactionType {
}
}
+ #[doc(hidden)]
pub fn decode(value: Value) -> Result<Self> {
let mut map = try!(into_map(value));
let name = try!(remove(&mut map, "name").and_then(into_string));
diff --git a/src/model/gateway.rs b/src/model/gateway.rs
index aa3d995..1a286af 100644
--- a/src/model/gateway.rs
+++ b/src/model/gateway.rs
@@ -734,6 +734,7 @@ impl Event {
}
impl Game {
+ #[cfg(feature="methods")]
pub fn playing(name: String) -> Game {
Game {
kind: GameType::Playing,
@@ -742,6 +743,7 @@ impl Game {
}
}
+ #[cfg(feature="methods")]
pub fn streaming(name: String, url: String) -> Game {
Game {
kind: GameType::Streaming,
@@ -750,6 +752,7 @@ impl Game {
}
}
+ #[doc(hidden)]
pub fn decode(value: Value) -> Result<Option<Game>> {
let mut map = try!(into_map(value));
@@ -771,6 +774,7 @@ impl Game {
}
impl Presence {
+ #[doc(hidden)]
pub fn decode(value: Value) -> Result<Presence> {
let mut value = try!(into_map(value));
let mut user_map = try!(remove(&mut value, "user").and_then(into_map));
diff --git a/src/model/guild.rs b/src/model/guild.rs
index 1ab9bb3..a350cae 100644
--- a/src/model/guild.rs
+++ b/src/model/guild.rs
@@ -1,6 +1,5 @@
-use serde_json::builder::ObjectBuilder;
use std::collections::HashMap;
-use std::{fmt, mem};
+use std::fmt;
use super::utils::{
decode_emojis,
decode_members,
@@ -14,11 +13,21 @@ use super::utils::{
warn_field
};
use super::*;
-use ::utils::builder::{EditGuild, EditMember, EditRole};
-use ::client::{STATE, http};
use ::internal::prelude::*;
use ::utils::decode_array;
+#[cfg(feature = "methods")]
+use serde_json::builder::ObjectBuilder;
+#[cfg(feature = "methods")]
+use std::mem;
+#[cfg(feature = "methods")]
+use ::utils::builder::{EditGuild, EditMember, EditRole};
+#[cfg(feature = "methods")]
+use ::client::http;
+
+#[cfg(feature = "state")]
+use ::client::STATE;
+
impl From<Guild> for GuildContainer {
fn from(guild: Guild) -> GuildContainer {
GuildContainer::Guild(guild)
@@ -41,6 +50,7 @@ impl Emoji {
/// Finds the [`Guild`] that owns the emoji by looking through the state.
///
/// [`Guild`]: struct.Guild.html
+ #[cfg(feature = "methods")]
pub fn find_guild_id(&self) -> Option<GuildId> {
STATE.lock()
.unwrap()
@@ -57,6 +67,7 @@ impl Emoji {
/// **Note**: Only user accounts may use this method.
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
+ #[cfg(feature = "methods")]
pub fn delete(&self) -> Result<()> {
match self.find_guild_id() {
Some(guild_id) => http::delete_emoji(guild_id.0, self.id.0),
@@ -71,6 +82,7 @@ impl Emoji {
/// **Note**: Only user accounts may use this method.
///
/// [Manage Emojis]: permissions/constant.MANAGE_EMOJIS.html
+ #[cfg(feature = "methods")]
pub fn edit(&mut self, name: &str) -> Result<()> {
match self.find_guild_id() {
Some(guild_id) => {
@@ -116,6 +128,7 @@ impl GuildInfo {
impl Guild {
/// Finds a role by Id within the guild.
+ #[cfg(feature = "methods")]
pub fn find_role<R: Into<RoleId>>(&self, role_id: R) -> Option<&Role> {
self.roles.get(&role_id.into())
}
@@ -127,6 +140,7 @@ impl Guild {
/// **Note**: Requires the [Change Nickname] permission.
///
/// [Change Nickname]: permissions/constant.CHANGE_NICKNAME.html
+ #[cfg(feature = "methods")]
#[inline]
pub fn edit_nickname(&self, new_nickname: Option<&str>) -> Result<()> {
http::edit_nickname(self.id.0, new_nickname)
@@ -143,6 +157,7 @@ impl Guild {
/// **Note**: Requires the [Manage Webhooks] permission.
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[cfg(feature = "methods")]
#[inline]
pub fn webhooks(&self) -> Result<Vec<Webhook>> {
http::get_guild_webhooks(self.id.0)
@@ -150,6 +165,7 @@ impl Guild {
}
impl LiveGuild {
+ #[cfg(feature = "state")]
fn has_perms(&self, mut permissions: Permissions) -> Result<bool> {
let member = match self.get_member(STATE.lock().unwrap().user.id) {
Some(member) => member,
@@ -163,6 +179,11 @@ impl LiveGuild {
Ok(permissions.is_empty())
}
+ #[cfg(not(feature = "state"))]
+ 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`.
@@ -190,6 +211,7 @@ impl LiveGuild {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ #[cfg(feature = "methods")]
pub fn ban<U: Into<UserId>>(&self, user: U, delete_message_days: u8)
-> Result<()> {
if delete_message_days > 7 {
@@ -217,6 +239,7 @@ impl LiveGuild {
/// [`Ban`]: struct.Ban.html
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ #[cfg(feature = "methods")]
pub fn bans(&self) -> Result<Vec<Ban>> {
let req = permissions::BAN_MEMBERS;
@@ -249,6 +272,7 @@ impl LiveGuild {
/// [`Channel`]: struct.Channel.html
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Manage Channels]: permissions/constants.MANAGE_CHANNELS.html
+ #[cfg(feature = "methods")]
pub fn create_channel(&mut self, name: &str, kind: ChannelType)
-> Result<Channel> {
let req = permissions::MANAGE_CHANNELS;
@@ -280,6 +304,7 @@ impl LiveGuild {
/// [`Context::create_role`]: ../client/struct.Context.html#method.create_role
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constants.MANAGE_ROLES.html
+ #[cfg(feature = "methods")]
pub fn create_role<F>(&self, f: F) -> Result<Role>
where F: FnOnce(EditRole) -> EditRole {
let req = permissions::MANAGE_ROLES;
@@ -352,6 +377,7 @@ impl LiveGuild {
/// guild owner.
///
/// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidUser
+ #[cfg(feature = "methods")]
pub fn delete(&self) -> Result<Guild> {
if self.owner_id != STATE.lock().unwrap().user.id {
let req = permissions::MANAGE_GUILD;
@@ -376,6 +402,7 @@ impl LiveGuild {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`Context::edit_guild`]: ../client/struct.Context.html#method.edit_guild
/// [Manage Guild]: permissions/constants.MANAGE_GUILD.html
+ #[cfg(feature = "methods")]
pub fn edit<F>(&mut self, f: F) -> Result<()>
where F: FnOnce(EditGuild) -> EditGuild {
let req = permissions::MANAGE_GUILD;
@@ -421,6 +448,7 @@ impl LiveGuild {
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Change Nickname]: permissions/constant.CHANGE_NICKNAME.html
+ #[cfg(feature = "methods")]
pub fn edit_nickname(&self, new_nickname: Option<&str>) -> Result<()> {
let req = permissions::CHANGE_NICKNAME;
@@ -450,6 +478,7 @@ impl LiveGuild {
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
+ #[cfg(feature = "methods")]
pub fn get_invites(&self) -> Result<Vec<RichInvite>> {
let req = permissions::MANAGE_GUILD;
@@ -526,6 +555,7 @@ impl LiveGuild {
}
/// Leaves the guild.
+ #[cfg(feature = "methods")]
pub fn leave(&self) -> Result<Guild> {
http::leave_guild(self.id.0)
}
@@ -655,6 +685,7 @@ impl LiveGuild {
/// [`GuildPrune`]: struct.GuildPrune.html
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
+ #[cfg(feature = "methods")]
pub fn prune_count(&self, days: u16) -> Result<GuildPrune> {
let req = permissions::KICK_MEMBERS;
@@ -684,6 +715,7 @@ impl LiveGuild {
/// [`GuildPrune`]: struct.GuildPrune.html
/// [`Member`]: struct.Member.html
/// [Kick Members]: permissions/constant.KICK_MEMBERS.html
+ #[cfg(feature = "methods")]
pub fn start_prune(&self, days: u16) -> Result<GuildPrune> {
let req = permissions::KICK_MEMBERS;
@@ -710,6 +742,7 @@ impl LiveGuild {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`User`]: struct.User.html
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ #[cfg(feature = "methods")]
pub fn unban<U: Into<UserId>>(&self, user: U) -> Result<()> {
let req = permissions::BAN_MEMBERS;
@@ -725,6 +758,7 @@ impl LiveGuild {
/// **Note**: Requires the [Manage Webhooks] permission.
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[cfg(feature = "methods")]
#[inline]
pub fn webhooks(&self) -> Result<Vec<Webhook>> {
http::get_guild_webhooks(self.id.0)
@@ -739,6 +773,7 @@ impl Member {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
+ #[cfg(feature = "methods")]
pub fn add_role<R: Into<RoleId>>(&mut self, role_id: R) -> Result<()> {
self.add_roles(&[role_id.into()])
}
@@ -750,6 +785,7 @@ impl Member {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
+ #[cfg(feature = "methods")]
pub fn add_roles(&mut self, role_ids: &[RoleId]) -> Result<()> {
let guild_id = try!(self.find_guild());
self.roles.extend_from_slice(role_ids);
@@ -772,6 +808,7 @@ impl Member {
/// **Note**: Requires the [Ban Members] role.
///
/// [Ban Members]: permissions/constant.BAN_MEMBERS.html
+ #[cfg(feature = "methods")]
pub fn ban(&self, delete_message_days: u8) -> Result<()> {
let guild_id = try!(self.find_guild());
@@ -795,6 +832,7 @@ impl Member {
///
/// [`Context::edit_member`]: ../client/struct.Context.html#method.edit_member
/// [`EditMember`]: ../builder/struct.EditMember.html
+ #[cfg(feature = "methods")]
pub fn edit<F>(&self, f: F) -> Result<()>
where F: FnOnce(EditMember) -> EditMember {
let guild_id = try!(self.find_guild());
@@ -806,6 +844,7 @@ impl Member {
/// Finds the Id of the [`Guild`] that the member is in.
///
/// [`Guild`]: struct.Guild.html
+ #[cfg(feature = "methods")]
pub fn find_guild(&self) -> Result<GuildId> {
STATE.lock()
.unwrap()
@@ -831,6 +870,7 @@ impl Member {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
+ #[cfg(feature = "methods")]
pub fn remove_role<R: Into<RoleId>>(&mut self, role_id: R) -> Result<()> {
self.remove_roles(&[role_id.into()])
}
@@ -841,6 +881,7 @@ impl Member {
///
/// [`Role`]: struct.Role.html
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
+ #[cfg(feature = "methods")]
pub fn remove_roles(&mut self, role_ids: &[RoleId]) -> Result<()> {
let guild_id = try!(self.find_guild());
self.roles.retain(|r| !role_ids.contains(r));
@@ -924,6 +965,7 @@ impl Role {
/// **Note** Requires the [Manage Roles] permission.
///
/// [Manage Roles]: permissions/constant.MANAGE_ROLES.html
+ #[cfg(feature = "methods")]
pub fn delete(&self) -> Result<()> {
let guild_id = try!(self.find_guild());
@@ -938,6 +980,7 @@ impl Role {
/// that contains the role.
///
/// [`ClientError::GuildNotFound`]: ../client/enum.ClientError.html#variant.GuildNotFound
+ #[cfg(feature = "methods")]
pub fn find_guild(&self) -> Result<GuildId> {
STATE.lock()
.unwrap()
diff --git a/src/model/id.rs b/src/model/id.rs
index 0d9fb32..ff236e1 100644
--- a/src/model/id.rs
+++ b/src/model/id.rs
@@ -1,15 +1,20 @@
use super::*;
+
+#[cfg(feature = "methods")]
use ::client::{STATE, http};
+#[cfg(feature = "methods")]
use ::internal::prelude::*;
impl ChannelId {
/// Search the state for the channel with the Id.
+ #[cfg(feature="methods")]
pub fn find(&self) -> Option<Channel> {
STATE.lock().unwrap().find_channel(*self)
}
/// Search the state for the channel. If it can't be found, the channel is
/// requested over REST.
+ #[cfg(feature="methods")]
pub fn get(&self) -> Result<Channel> {
if let Some(channel) = STATE.lock().unwrap().find_channel(*self) {
return Ok(channel);
@@ -34,6 +39,7 @@ impl ChannelId {
/// **Note**: Requires the [Manage Webhooks] permission.
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[cfg(feature="methods")]
pub fn webhooks(&self) -> Result<Vec<Webhook>> {
http::get_channel_webhooks(self.0)
}
@@ -69,6 +75,7 @@ impl From<Emoji> for EmojiId {
impl GuildId {
/// Search the state for the guild.
+ #[cfg(feature="methods")]
pub fn find(&self) -> Option<LiveGuild> {
STATE.lock().unwrap().find_guild(*self).cloned()
}
@@ -77,6 +84,7 @@ impl GuildId {
///
/// Note that this will not be a complete guild, as REST does not send
/// all data with a guild retrieval.
+ #[cfg(feature="methods")]
pub fn get(&self) -> Result<Guild> {
http::get_guild(self.0)
}
@@ -96,6 +104,7 @@ impl GuildId {
/// **Note**: Requires the [Manage Webhooks] permission.
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[cfg(feature="methods")]
pub fn webhooks(&self) -> Result<Vec<Webhook>> {
http::get_guild_webhooks(self.0)
}
@@ -145,6 +154,7 @@ impl From<Role> for RoleId {
impl RoleId {
/// Search the state for the role.
+ #[cfg(feature="methods")]
pub fn find(&self) -> Option<Role> {
STATE.lock()
.unwrap()
@@ -206,6 +216,7 @@ impl WebhookId {
/// **Note**: Requires the [Manage Webhooks] permission.
///
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[cfg(feature="methods")]
pub fn webhooks(&self) -> Result<Webhook> {
http::get_webhook(self.0)
}
diff --git a/src/model/invite.rs b/src/model/invite.rs
index 8fd55e7..c33647e 100644
--- a/src/model/invite.rs
+++ b/src/model/invite.rs
@@ -10,6 +10,7 @@ impl Invite {
/// banned. A ban is equivilant to an IP ban.
///
/// [`Guild`]: struct.Guild.html
+ #[cfg(feature="methods")]
pub fn accept(&self) -> Result<Invite> {
http::accept_invite(&self.code)
}
@@ -25,6 +26,7 @@ impl Invite {
///
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
+ #[cfg(feature="methods")]
pub fn delete(&self) -> Result<Invite> {
let req = permissions::MANAGE_GUILD;
@@ -43,6 +45,7 @@ impl RichInvite {
/// accepting an invite.
///
/// [`Invite::accept`]: struct.Invite.html#method.accept
+ #[cfg(feature="methods")]
pub fn accept(&self) -> Result<Invite> {
http::accept_invite(&self.code)
}
@@ -60,6 +63,7 @@ impl RichInvite {
/// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
/// [`Invite::delete`]: struct.Invite.html#method.delete
/// [Manage Guild]: permissions/constant.MANAGE_GUILD.html
+ #[cfg(feature="methods")]
pub fn delete(&self) -> Result<Invite> {
let req = permissions::MANAGE_GUILD;
diff --git a/src/model/misc.rs b/src/model/misc.rs
index 16cc7fe..3a17d96 100644
--- a/src/model/misc.rs
+++ b/src/model/misc.rs
@@ -89,6 +89,7 @@ impl fmt::Display for Mention {
}
impl IncidentStatus {
+ #[doc(hidden)]
pub fn decode(value: Value) -> Result<Self> {
Self::decode_str(value)
}
diff --git a/src/model/mod.rs b/src/model/mod.rs
index f21da09..f00dffb 100644
--- a/src/model/mod.rs
+++ b/src/model/mod.rs
@@ -7,21 +7,27 @@ mod channel;
mod gateway;
mod guild;
mod id;
-mod invite;
mod misc;
mod user;
mod voice;
+
+#[cfg(feature = "methods")]
+mod invite;
+#[cfg(feature = "methods")]
mod webhook;
pub use self::channel::*;
pub use self::gateway::*;
pub use self::guild::*;
pub use self::id::*;
-pub use self::invite::*;
pub use self::misc::*;
pub use self::permissions::Permissions;
pub use self::user::*;
pub use self::voice::*;
+
+#[cfg(feature = "methods")]
+pub use self::invite::*;
+#[cfg(feature = "methods")]
pub use self::webhook::*;
use self::utils::*;
diff --git a/src/model/permissions.rs b/src/model/permissions.rs
index 49a5069..c21e441 100644
--- a/src/model/permissions.rs
+++ b/src/model/permissions.rs
@@ -82,6 +82,7 @@ use ::internal::prelude::*;
/// [Speak]: constant.SPEAK.html
/// [Use External Emojis]: constant.USE_EXTERNAL_EMOJIS.html
/// [Use VAD]: constant.USE_VAD.html
+#[cfg(feature="extras")]
pub fn general() -> Permissions {
use self::*;
@@ -119,6 +120,7 @@ pub fn general() -> Permissions {
/// [Send Messages]: constant.SEND_MESSAGES.html
/// [Send TTS Messages]: constant.SEND_TTS_MESSAGES.html
/// [Use External Emojis]: constant.USE_EXTERNAL_EMOJIS.html
+#[cfg(feature="extras")]
pub fn text() -> Permissions {
use self::*;
@@ -140,6 +142,7 @@ pub fn text() -> Permissions {
/// [Connect]: constant.CONNECT.html
/// [Speak]: constant.SPEAK.html
/// [Use VAD]: constant.USE_VAD.html
+#[cfg(feature="extras")]
pub fn voice() -> Permissions {
use self::*;
diff --git a/src/model/user.rs b/src/model/user.rs
index f748d67..ce3d3a5 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -1,4 +1,3 @@
-use serde_json::builder::ObjectBuilder;
use std::fmt;
use super::utils::{into_map, into_string, remove, warn_field};
use super::{
@@ -6,15 +5,23 @@ use super::{
GuildContainer,
GuildId,
Mention,
- Message,
RoleId,
UserSettings,
User
};
-use ::client::{STATE, http};
use ::internal::prelude::*;
use ::utils::decode_array;
+#[cfg(feature = "methods")]
+use serde_json::builder::ObjectBuilder;
+#[cfg(feature = "methods")]
+use super::Message;
+#[cfg(feature = "methods")]
+use ::client::http;
+
+#[cfg(feature = "state")]
+use ::client::STATE;
+
impl User {
/// Returns the formatted URL of the user's icon, if one exists.
pub fn avatar_url(&self) -> Option<String> {
@@ -25,6 +32,7 @@ impl User {
/// This is an alias of [direct_message].
///
/// [direct_message]: #method.direct_message
+ #[cfg(feature="methods")]
pub fn dm(&self, content: &str) -> Result<Message> {
self.direct_message(content)
}
@@ -32,6 +40,7 @@ impl User {
/// Send a direct message to a user. This will create or retrieve the
/// PrivateChannel over REST if one is not already in the State, and then
/// send a message to it.
+ #[cfg(feature="methods")]
pub fn direct_message(&self, content: &str)
-> Result<Message> {
let private_channel_id = {
@@ -94,12 +103,16 @@ impl User {
match guild.into() {
GuildContainer::Guild(guild) => {
- guild.find_role(role_id).is_some()
+ guild.roles.get(&role_id).is_some()
},
GuildContainer::Id(guild_id) => {
- let state = STATE.lock().unwrap();
+ feature_state! {{
+ let state = STATE.lock().unwrap();
- state.find_role(guild_id, role_id).is_some()
+ state.find_role(guild_id, role_id).is_some()
+ } else {
+ true
+ }}
},
}
}
diff --git a/src/model/utils.rs b/src/model/utils.rs
index f85a30f..92dfbd9 100644
--- a/src/model/utils.rs
+++ b/src/model/utils.rs
@@ -1,5 +1,4 @@
use std::collections::{BTreeMap, HashMap};
-use super::permissions::{self, Permissions};
use super::{
Channel,
ChannelId,
@@ -15,10 +14,14 @@ use super::{
UserId,
VoiceState,
};
-use ::client::STATE;
use ::internal::prelude::*;
use ::utils::{decode_array, into_array};
+#[cfg(feature = "methods")]
+use super::permissions::{self, Permissions};
+#[cfg(feature = "methods")]
+use ::client::STATE;
+
#[macro_escape]
macro_rules! missing {
(@ $name:expr, $json:ident, $value:expr) => {
@@ -268,6 +271,7 @@ pub fn remove(map: &mut BTreeMap<String, Value>, key: &str) -> Result<Value> {
}
#[doc(hidden)]
+#[cfg(feature="methods")]
pub fn user_has_perms(channel_id: ChannelId,
mut permissions: Permissions)
-> Result<bool> {
diff --git a/src/model/webhook.rs b/src/model/webhook.rs
index 04f6d5d..f0d7b16 100644
--- a/src/model/webhook.rs
+++ b/src/model/webhook.rs
@@ -12,6 +12,7 @@ impl Webhook {
/// authentication is not required.
///
/// [`http::delete_webhook_with_token`]: ../client/http/fn.delete_webhook_with_token.html
+ #[cfg(feature="methods")]
pub fn delete(&self) -> Result<()> {
http::delete_webhook_with_token(self.id.0, &self.token)
}
@@ -62,6 +63,7 @@ impl Webhook {
///
/// [`http::edit_webhook`]: ../client/http/fn.edit_webhook.html
/// [`http::edit_webhook_with_token`]: ../client/http/fn.edit_webhook_with_token.html
+ #[cfg(feature="methods")]
pub fn edit(&mut self, name: Option<&str>, avatar: Option<&str>)
-> Result<()> {
if name.is_none() && avatar.is_none() {
@@ -141,6 +143,7 @@ impl Webhook {
/// .embeds(vec![embed]))
/// .expect("err executing");
/// ```
+ #[cfg(feature="methods")]
pub fn execute<F>(&self, f: F) -> Result<Message>
where F: FnOnce(ExecuteWebhook) -> ExecuteWebhook {
let map = f(ExecuteWebhook::default()).0.build();
@@ -155,6 +158,7 @@ impl Webhook {
/// authentication is not required.
///
/// [`http::get_webhook_with_token`]: ../client/http/fn.get_webhook_with_token.html
+ #[cfg(feature="methods")]
pub fn refresh(&mut self) -> Result<()> {
match http::get_webhook_with_token(self.id.0, &self.token) {
Ok(replacement) => {