aboutsummaryrefslogtreecommitdiff
path: root/src/model/channel
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-05-22 17:02:00 -0700
committerZeyla Hellyer <[email protected]>2017-05-22 17:02:00 -0700
commit9969be60cf320797c37b317da24d9a08fd5eafa5 (patch)
treef27bf7a57af95bbc11990b1edcea9cca99276964 /src/model/channel
parentReasonably derive Debug on items (diff)
downloadserenity-9969be60cf320797c37b317da24d9a08fd5eafa5.tar.xz
serenity-9969be60cf320797c37b317da24d9a08fd5eafa5.zip
Restructure modules
Modules are now separated into a fashion where the library can be used for most use cases, without needing to compile the rest. The core of serenity, with no features enabled, contains only the struct (model) definitions, constants, and prelude. Models do not have most functions compiled in, as that is separated into the `model` feature. The `client` module has been split into 3 modules: `client`, `gateway`, and `http`. `http` contains functions to interact with the REST API. `gateway` contains the Shard to interact with the gateway, requiring `http` for retrieving the gateway URL. `client` requires both of the other features and acts as an abstracted interface over both the gateway and REST APIs, handling the event loop. The `builder` module has been separated from `utils`, and can now be optionally compiled in. It and the `http` feature are required by the `model` feature due to a large number of methods requiring access to them. `utils` now contains a number of utilities, such as the Colour struct, the `MessageBuilder`, and mention parsing functions. Each of the original `ext` modules are still featured, with `cache` not requiring any feature to be enabled, `framework` requiring the `client`, `model`, and `utils`, and `voice` requiring `gateway`. In total the features and their requirements are: - `builder`: none - `cache`: none - `client`: `gateway`, `http` - `framework`: `client`, `model`, `utils` - `gateway`: `http` - `http`: none - `model`: `builder`, `http` - `utils`: none - `voice`: `gateway` The default features are `builder`, `cache`, `client`, `framework`, `gateway`, `model`, `http`, and `utils`. To help with forwards compatibility, modules have been re-exported from their original locations.
Diffstat (limited to 'src/model/channel')
-rw-r--r--src/model/channel/attachment.rs2
-rw-r--r--src/model/channel/channel_id.rs87
-rw-r--r--src/model/channel/embed.rs14
-rw-r--r--src/model/channel/group.rs36
-rw-r--r--src/model/channel/guild_channel.rs73
-rw-r--r--src/model/channel/message.rs84
-rw-r--r--src/model/channel/mod.rs35
-rw-r--r--src/model/channel/private_channel.rs27
-rw-r--r--src/model/channel/reaction.rs21
9 files changed, 207 insertions, 172 deletions
diff --git a/src/model/channel/attachment.rs b/src/model/channel/attachment.rs
index 17e3076..b7f371b 100644
--- a/src/model/channel/attachment.rs
+++ b/src/model/channel/attachment.rs
@@ -1,3 +1,4 @@
+#[cfg(feature="model")]
use hyper::Client as HyperClient;
use std::io::Read;
use ::internal::prelude::*;
@@ -24,6 +25,7 @@ pub struct Attachment {
pub width: Option<u64>,
}
+#[cfg(feature="model")]
impl Attachment {
/// If this attachment is an image, then a tuple of the width and height
/// in pixels is returned.
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index 46b00c6..3967dba 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -1,12 +1,15 @@
use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite};
use std::io::Read;
-use ::client::rest;
use ::model::*;
-use ::utils::builder::{CreateMessage, EditChannel, GetMessages};
+#[cfg(feature="model")]
+use ::builder::{CreateMessage, EditChannel, GetMessages};
#[cfg(feature="cache")]
-use ::client::CACHE;
+use ::CACHE;
+#[cfg(feature="model")]
+use ::http;
+#[cfg(feature="model")]
impl ChannelId {
/// Broadcasts that the current user is typing to a channel for the next 5
/// seconds.
@@ -30,7 +33,7 @@ impl ChannelId {
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn broadcast_typing(&self) -> Result<()> {
- rest::broadcast_typing(self.0)
+ http::broadcast_typing(self.0)
}
/// Creates a [permission overwrite][`PermissionOverwrite`] for either a
@@ -60,7 +63,7 @@ impl ChannelId {
"type": kind,
});
- rest::create_permission(self.0, id, &map)
+ http::create_permission(self.0, id, &map)
}
/// React to a [`Message`] with a custom [`Emoji`] or unicode character.
@@ -78,13 +81,13 @@ impl ChannelId {
#[inline]
pub fn create_reaction<M, R>(&self, message_id: M, reaction_type: R)
-> Result<()> where M: Into<MessageId>, R: Into<ReactionType> {
- rest::create_reaction(self.0, message_id.into().0, &reaction_type.into())
+ http::create_reaction(self.0, message_id.into().0, &reaction_type.into())
}
/// Deletes this channel, returning the channel on a successful deletion.
#[inline]
pub fn delete(&self) -> Result<Channel> {
- rest::delete_channel(self.0)
+ http::delete_channel(self.0)
}
/// Deletes a [`Message`] given its Id.
@@ -99,7 +102,7 @@ impl ChannelId {
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
#[inline]
pub fn delete_message<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- rest::delete_message(self.0, message_id.into().0)
+ http::delete_message(self.0, message_id.into().0)
}
/// Deletes all messages by Ids from the given vector in the given channel.
@@ -125,7 +128,7 @@ impl ChannelId {
"messages": ids
});
- rest::delete_messages(self.0, &map)
+ http::delete_messages(self.0, &map)
}
/// Deletes all permission overrides in the channel from a member or role.
@@ -134,7 +137,7 @@ impl ChannelId {
///
/// [Manage Channel]: permissions/constant.MANAGE_CHANNELS.html
pub fn delete_permission(&self, permission_type: PermissionOverwriteType) -> Result<()> {
- rest::delete_permission(self.0, match permission_type {
+ http::delete_permission(self.0, match permission_type {
PermissionOverwriteType::Member(id) => id.0,
PermissionOverwriteType::Role(id) => id.0,
})
@@ -149,7 +152,7 @@ impl ChannelId {
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
pub fn delete_reaction<M, R>(&self, message_id: M, user_id: Option<UserId>, reaction_type: R)
-> Result<()> where M: Into<MessageId>, R: Into<ReactionType> {
- rest::delete_reaction(self.0,
+ http::delete_reaction(self.0,
message_id.into().0,
user_id.map(|uid| uid.0),
&reaction_type.into())
@@ -172,17 +175,11 @@ impl ChannelId {
/// channel_id.edit(|c| c.name("test").bitrate(64000));
/// ```
///
- /// # Errors
- ///
- /// Returns a [`ClientError::NoChannelId`] if the current context is not
- /// related to a channel.
- ///
/// [`Channel`]: enum.Channel.html
- /// [`ClientError::NoChannelId`]: ../client/enum.ClientError.html#variant.NoChannelId
/// [Manage Channel]: permissions/constant.MANAGE_CHANNELS.html
#[inline]
pub fn edit<F: FnOnce(EditChannel) -> EditChannel>(&self, f: F) -> Result<GuildChannel> {
- rest::edit_channel(self.0, &f(EditChannel::default()).0)
+ http::edit_channel(self.0, &f(EditChannel::default()).0)
}
/// Edits a [`Message`] in the channel given its Id.
@@ -196,14 +193,14 @@ impl ChannelId {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the [`the limit`], containing the number of unicode code points
/// over the limit.
///
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [`Message`]: struct.Message.html
- /// [`the limit`]: ../utils/builder/struct.CreateMessage.html#method.content
+ /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content
pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> {
let map = f(CreateMessage::default()).0;
@@ -211,12 +208,12 @@ impl ChannelId {
if let Some(content) = map.get("content") {
if let Value::String(ref content) = *content {
if let Some(length_over) = Message::overflow_length(content) {
- return Err(Error::Client(ClientError::MessageTooLong(length_over)));
+ return Err(Error::Model(ModelError::MessageTooLong(length_over)));
}
}
}
- rest::edit_message(self.0, message_id.into().0, &Value::Object(map))
+ http::edit_message(self.0, message_id.into().0, &Value::Object(map))
}
/// Search the cache for the channel with the Id.
@@ -235,7 +232,7 @@ impl ChannelId {
}
}
- rest::get_channel(self.0)
+ http::get_channel(self.0)
}
/// Gets all of the channel's invites.
@@ -244,7 +241,7 @@ impl ChannelId {
/// [Manage Channels]: permissions/constant.MANAGE_CHANNELS.html
#[inline]
pub fn invites(&self) -> Result<Vec<RichInvite>> {
- rest::get_channel_invites(self.0)
+ http::get_channel_invites(self.0)
}
/// Gets a message from the channel.
@@ -254,7 +251,7 @@ impl ChannelId {
/// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
#[inline]
pub fn message<M: Into<MessageId>>(&self, message_id: M) -> Result<Message> {
- rest::get_message(self.0, message_id.into().0)
+ http::get_message(self.0, message_id.into().0)
.map(|mut msg| {
msg.transform_content();
@@ -283,7 +280,7 @@ impl ChannelId {
write!(query, "&before={}", before)?;
}
- rest::get_messages(self.0, &query)
+ http::get_messages(self.0, &query)
.map(|msgs| msgs
.into_iter()
.map(|mut msg| {
@@ -298,7 +295,7 @@ impl ChannelId {
/// [`Message`]: struct.Message.html
#[inline]
pub fn pin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- rest::pin_message(self.0, message_id.into().0)
+ http::pin_message(self.0, message_id.into().0)
}
/// Gets the list of [`Message`]s which are pinned to the channel.
@@ -306,7 +303,7 @@ impl ChannelId {
/// [`Message`]: struct.Message.html
#[inline]
pub fn pins(&self) -> Result<Vec<Message>> {
- rest::get_pins(self.0)
+ http::get_pins(self.0)
}
/// Gets the list of [`User`]s who have reacted to a [`Message`] with a
@@ -329,7 +326,7 @@ impl ChannelId {
-> Result<Vec<User>> where M: Into<MessageId>, R: Into<ReactionType>, U: Into<UserId> {
let limit = limit.map_or(50, |x| if x > 100 { 100 } else { x });
- rest::get_reaction_users(self.0,
+ http::get_reaction_users(self.0,
message_id.into().0,
&reaction_type.into(),
limit,
@@ -340,12 +337,12 @@ impl ChannelId {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
- /// [`ChannelId`]: ../model/struct.ChannelId.html
- /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
+ /// [`ChannelId`]: struct.ChannelId.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
#[inline]
pub fn say(&self, content: &str) -> Result<Message> {
self.send_message(|m| m.content(content))
@@ -382,11 +379,11 @@ impl ChannelId {
/// # Errors
///
/// If the content of the message is over the above limit, then a
- /// [`ClientError::MessageTooLong`] will be returned, containing the number
+ /// [`ModelError::MessageTooLong`] will be returned, containing the number
/// of unicode code points over the limit.
///
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage::content`]: ../utils/builder/struct.CreateMessage.html#method.content
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage::content`]: ../builder/struct.CreateMessage.html#method.content
/// [`GuildChannel`]: struct.GuildChannel.html
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
@@ -397,14 +394,14 @@ impl ChannelId {
if let Some(content) = map.get("content") {
if let Value::String(ref content) = *content {
if let Some(length_over) = Message::overflow_length(content) {
- return Err(Error::Client(ClientError::MessageTooLong(length_over)));
+ return Err(Error::Model(ModelError::MessageTooLong(length_over)));
}
}
}
let _ = map.remove("embed");
- rest::send_file(self.0, file, filename, map)
+ http::send_file(self.0, file, filename, map)
}
/// Sends a message to the channel.
@@ -418,13 +415,13 @@ impl ChannelId {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
/// [`Channel`]: enum.Channel.html
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_message<F>(&self, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage {
@@ -433,7 +430,7 @@ impl ChannelId {
Message::check_content_length(&map)?;
Message::check_embed_length(&map)?;
- rest::send_message(self.0, &Value::Object(map))
+ http::send_message(self.0, &Value::Object(map))
}
/// Unpins a [`Message`] in the channel given by its Id.
@@ -444,7 +441,7 @@ impl ChannelId {
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
#[inline]
pub fn unpin<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- rest::unpin_message(self.0, message_id.into().0)
+ http::unpin_message(self.0, message_id.into().0)
}
/// Retrieves the channel's webhooks.
@@ -454,7 +451,7 @@ impl ChannelId {
/// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
#[inline]
pub fn webhooks(&self) -> Result<Vec<Webhook>> {
- rest::get_channel_webhooks(self.0)
+ http::get_channel_webhooks(self.0)
}
/// Alias of [`invites`].
diff --git a/src/model/channel/embed.rs b/src/model/channel/embed.rs
index b278622..9e35ea5 100644
--- a/src/model/channel/embed.rs
+++ b/src/model/channel/embed.rs
@@ -1,7 +1,11 @@
-use ::utils::builder::CreateEmbed;
-use ::utils::Colour;
use ::internal::prelude::*;
+#[cfg(feature="utils")]
+use ::utils::Colour;
+
+#[cfg(feature="model")]
+use ::builder::CreateEmbed;
+
/// Represents a rich embed which allows using richer markdown, multiple fields
/// and more. This was heavily inspired by [slack's attachments].
///
@@ -17,8 +21,13 @@ pub struct Embed {
/// Information about the author of the embed.
pub author: Option<EmbedAuthor>,
/// The colour code of the embed.
+ #[cfg(feature="utils")]
#[serde(default, rename="color")]
pub colour: Colour,
+ /// The colour code of the embed.
+ #[cfg(not(feature="utils"))]
+ #[serde(default, rename="color")]
+ pub colour: u32,
/// The description of the embed.
///
/// The maximum value for this field is 2048 unicode codepoints.
@@ -53,6 +62,7 @@ pub struct Embed {
pub video: Option<EmbedVideo>,
}
+#[cfg(feature="model")]
impl Embed {
/// Creates a fake Embed, giving back a `serde_json` map.
///
diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs
index bf87590..adafdc8 100644
--- a/src/model/channel/group.rs
+++ b/src/model/channel/group.rs
@@ -1,9 +1,12 @@
use std::borrow::Cow;
use std::fmt::Write as FmtWrite;
use std::io::Read;
-use ::client::rest;
use ::model::*;
-use ::utils::builder::{CreateMessage, GetMessages};
+
+#[cfg(feature="model")]
+use ::builder::{CreateMessage, GetMessages};
+#[cfg(feature="model")]
+use ::http;
/// A group channel - potentially including other [`User`]s - separate from a
/// [`Guild`].
@@ -30,16 +33,17 @@ pub struct Group {
pub recipients: HashMap<UserId, Arc<RwLock<User>>>,
}
+#[cfg(feature="model")]
impl Group {
/// Adds the given user to the group. If the user is already in the group,
/// then nothing is done.
///
- /// Refer to [`rest::add_group_recipient`] for more information.
+ /// Refer to [`http::add_group_recipient`] for more information.
///
/// **Note**: Groups have a limit of 10 recipients, including the current
/// user.
///
- /// [`rest::add_group_recipient`]: ../client/rest/fn.add_group_recipient.html
+ /// [`http::add_group_recipient`]: ../http/fn.add_group_recipient.html
pub fn add_recipient<U: Into<UserId>>(&self, user: U) -> Result<()> {
let user = user.into();
@@ -48,7 +52,7 @@ impl Group {
return Ok(());
}
- rest::add_group_recipient(self.channel_id.0, user.0)
+ http::add_group_recipient(self.channel_id.0, user.0)
}
/// Broadcasts that the current user is typing in the group.
@@ -129,14 +133,14 @@ impl Group {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the [`the limit`], containing the number of unicode code points
/// over the limit.
///
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [`Message`]: struct.Message.html
- /// [`the limit`]: ../utils/builder/struct.CreateMessage.html#method.content
+ /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content
#[inline]
pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> {
@@ -165,7 +169,7 @@ impl Group {
/// Leaves the group.
#[inline]
pub fn leave(&self) -> Result<Group> {
- rest::leave_group(self.channel_id.0)
+ http::leave_group(self.channel_id.0)
}
/// Gets a message from the channel.
@@ -252,19 +256,19 @@ impl Group {
return Ok(());
}
- rest::remove_group_recipient(self.channel_id.0, user.0)
+ http::remove_group_recipient(self.channel_id.0, user.0)
}
/// Sends a message with just the given message content in the channel.
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
/// [`ChannelId`]: ../model/struct.ChannelId.html
- /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
#[inline]
pub fn say(&self, content: &str) -> Result<Message> {
self.channel_id.say(content)
@@ -282,11 +286,11 @@ impl Group {
/// # Errors
///
/// If the content of the message is over the above limit, then a
- /// [`ClientError::MessageTooLong`] will be returned, containing the number
+ /// [`ModelError::MessageTooLong`] will be returned, containing the number
/// of unicode code points over the limit.
///
/// [`ChannelId::send_file`]: struct.ChannelId.html#method.send_file
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_file<F, R>(&self, file: R, filename: &str, f: F) -> Result<Message>
@@ -301,7 +305,7 @@ impl Group {
///
/// **Note**: Requires the [Send Messages] permission.
///
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message> {
diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs
index 7f05b4f..7180017 100644
--- a/src/model/channel/guild_channel.rs
+++ b/src/model/channel/guild_channel.rs
@@ -1,14 +1,17 @@
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::io::Read;
use std::mem;
-use ::client::rest;
use ::internal::prelude::*;
use ::model::*;
-use ::utils::builder::{CreateInvite, CreateMessage, EditChannel, GetMessages};
-use ::utils as serenity_utils;
+#[cfg(feature="model")]
+use ::builder::{CreateInvite, CreateMessage, EditChannel, GetMessages};
#[cfg(feature="cache")]
-use ::client::CACHE;
+use ::CACHE;
+#[cfg(feature="model")]
+use ::http;
+#[cfg(all(feature="model", feature="utils"))]
+use ::utils as serenity_utils;
/// Represents a guild's text or voice channel. Some methods are available only
/// for voice channels and some are only available for text channels.
@@ -62,6 +65,7 @@ pub struct GuildChannel {
pub user_limit: Option<u64>,
}
+#[cfg(feature="model")]
impl GuildChannel {
/// Broadcasts to the channel that the current user is typing.
///
@@ -71,10 +75,10 @@ impl GuildChannel {
///
/// # Errors
///
- /// Returns a [`ClientError::InvalidPermissions`] if the current user does
+ /// Returns a [`ModelError::InvalidPermissions`] if the current user does
/// not have the required permissions.
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn broadcast_typing(&self) -> Result<()> {
self.id.broadcast_typing()
@@ -96,11 +100,11 @@ impl GuildChannel {
let req = permissions::CREATE_INVITE;
if !utils::user_has_perms(self.id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
- rest::create_invite(self.id.0, &f(CreateInvite::default()).0)
+ http::create_invite(self.id.0, &f(CreateInvite::default()).0)
}
/// Creates a [permission overwrite][`PermissionOverwrite`] for either a
@@ -119,8 +123,8 @@ impl GuildChannel {
/// permissions:
///
/// ```rust,ignore
- /// use serenity::client::CACHE;
/// use serenity::model::{ChannelId, PermissionOverwrite, permissions};
+ /// use serenity::CACHE;
///
/// let channel_id = 7;
/// let user_id = 8;
@@ -145,8 +149,8 @@ impl GuildChannel {
/// permissions:
///
/// ```rust,ignore
- /// use serenity::client::CACHE;
/// use serenity::model::{ChannelId, PermissionOverwrite, permissions};
+ /// use serenity::CACHE;
///
/// let channel_id = 7;
/// let user_id = 8;
@@ -187,7 +191,7 @@ impl GuildChannel {
let req = permissions::MANAGE_CHANNELS;
if !utils::user_has_perms(self.id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -256,7 +260,7 @@ impl GuildChannel {
let req = permissions::MANAGE_CHANNELS;
if !utils::user_has_perms(self.id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -267,7 +271,7 @@ impl GuildChannel {
let edited = f(EditChannel(map)).0;
- match rest::edit_channel(self.id.0, &edited) {
+ match http::edit_channel(self.id.0, &edited) {
Ok(channel) => {
mem::replace(self, channel);
@@ -288,14 +292,14 @@ impl GuildChannel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the [`the limit`], containing the number of unicode code points
/// over the limit.
///
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [`Message`]: struct.Message.html
- /// [`the limit`]: ../utils/builder/struct.CreateMessage.html#method.content
+ /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content
#[inline]
pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> {
@@ -330,6 +334,7 @@ impl GuildChannel {
/// [`ChannelType::Text`]: enum.ChannelType.html#variant.Text
/// [`ChannelType::Voice`]: enum.ChannelType.html#variant.Voice
/// [`utils::is_nsfw`]: ../utils/fn.is_nsfw.html
+ #[cfg(feature="utils")]
#[inline]
pub fn is_nsfw(&self) -> bool {
self.kind == ChannelType::Text && serenity_utils::is_nsfw(&self.name)
@@ -374,7 +379,7 @@ impl GuildChannel {
/// #
/// # let mut client = Client::login("");
/// #
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
///
/// client.on_message(|_, msg| {
/// let channel = match CACHE.read().unwrap().get_guild_channel(msg.channel_id) {
@@ -397,7 +402,7 @@ impl GuildChannel {
/// #
/// # let mut client = Client::login("");
/// #
- /// use serenity::client::CACHE;
+ /// use serenity::CACHE;
/// use serenity::model::permissions;
/// use std::fs::File;
///
@@ -429,20 +434,21 @@ impl GuildChannel {
///
/// # Errors
///
- /// Returns a [`ClientError::GuildNotFound`] if the channel's guild could
+ /// Returns a [`ModelError::GuildNotFound`] if the channel's guild could
/// not be found in the [`Cache`].
///
- /// [`Cache`]: ../ext/cache/struct.Cache.html
- /// [`ClientError::GuildNotFound`]: ../client/enum.Error.html#variant.GuildNotFound
+ /// [`Cache`]: ../cache/struct.Cache.html
+ /// [`ModelError::GuildNotFound`]: enum.ModelError.html#variant.GuildNotFound
/// [`Guild`]: struct.Guild.html
/// [`Member`]: struct.Member.html
/// [`Message`]: struct.Message.html
/// [`User`]: struct.User.html
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
+ #[cfg(feature="cache")]
pub fn permissions_for<U: Into<UserId>>(&self, user_id: U) -> Result<Permissions> {
self.guild()
- .ok_or_else(|| Error::Client(ClientError::GuildNotFound))
+ .ok_or_else(|| Error::Model(ModelError::GuildNotFound))
.map(|g| g.read().unwrap().permissions_for(self.id, user_id))
}
@@ -483,12 +489,12 @@ impl GuildChannel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
- /// [`ChannelId`]: ../model/struct.ChannelId.html
- /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
+ /// [`ChannelId`]: struct.ChannelId.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
#[inline]
pub fn say(&self, content: &str) -> Result<Message> {
self.id.say(content)
@@ -506,11 +512,11 @@ impl GuildChannel {
/// # Errors
///
/// If the content of the message is over the above limit, then a
- /// [`ClientError::MessageTooLong`] will be returned, containing the number
+ /// [`ModelError::MessageTooLong`] will be returned, containing the number
/// of unicode code points over the limit.
///
/// [`ChannelId::send_file`]: struct.ChannelId.html#method.send_file
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_file<F, R>(&self, file: R, filename: &str, f: F) -> Result<Message>
@@ -526,15 +532,15 @@ impl GuildChannel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
- /// Returns a [`ClientError::InvalidPermissions`] if the current user does
+ /// Returns a [`ModelError::InvalidPermissions`] if the current user does
/// not have the required permissions.
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
/// [`Message`]: struct.Message.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message> {
@@ -543,7 +549,7 @@ impl GuildChannel {
let req = permissions::SEND_MESSAGES;
if !utils::user_has_perms(self.id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -623,6 +629,7 @@ impl GuildChannel {
}
}
+#[cfg(feature="model")]
impl Display for GuildChannel {
/// Formats the channel, creating a mention of it.
fn fmt(&self, f: &mut Formatter) -> FmtResult {
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs
index 91f6c89..30f5850 100644
--- a/src/model/channel/message.rs
+++ b/src/model/channel/message.rs
@@ -1,14 +1,17 @@
use std::mem;
use time;
use ::constants;
-use ::client::rest;
use ::model::*;
-use ::utils::builder::{CreateEmbed, CreateMessage};
+
#[cfg(feature="cache")]
use std::fmt::Write;
+#[cfg(feature="model")]
+use ::builder::{CreateEmbed, CreateMessage};
#[cfg(feature="cache")]
-use ::client::CACHE;
+use ::CACHE;
+#[cfg(feature="http")]
+use ::http;
/// A representation of a message over a guild's text channel, a group, or a
/// private channel.
@@ -61,6 +64,7 @@ pub struct Message {
pub webhook_id: Option<WebhookId>,
}
+#[cfg(feature="model")]
impl Message {
/// Deletes the message.
///
@@ -70,11 +74,11 @@ impl Message {
/// # Errors
///
/// If the `cache` feature is enabled, then returns a
- /// [`ClientError::InvalidPermissions`] if the current user does not have
+ /// [`ModelError::InvalidPermissions`] if the current user does not have
/// the required permissions.
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
- /// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidUser
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
+ /// [`ModelError::InvalidUser`]: enum.ModelError.html#variant.InvalidUser
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
pub fn delete(&self) -> Result<()> {
#[cfg(feature="cache")]
@@ -84,7 +88,7 @@ impl Message {
let has_perms = utils::user_has_perms(self.channel_id, req)?;
if !is_author && !has_perms {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -98,10 +102,10 @@ impl Message {
/// # Errors
///
/// If the `cache` feature is enabled, then returns a
- /// [`ClientError::InvalidPermissions`] if the current user does not have
+ /// [`ModelError::InvalidPermissions`] if the current user does not have
/// the required permissions.
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [`Reaction`]: struct.Reaction.html
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
pub fn delete_reactions(&self) -> Result<()> {
@@ -110,11 +114,11 @@ impl Message {
let req = permissions::MANAGE_MESSAGES;
if !utils::user_has_perms(self.channel_id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
- rest::delete_message_reactions(self.channel_id.0, self.id.0)
+ http::delete_message_reactions(self.channel_id.0, self.id.0)
}
/// Edits this message, replacing the original content with new content.
@@ -138,23 +142,23 @@ impl Message {
///
/// # Errors
///
- /// If the `cache` is enabled, returns a [`ClientError::InvalidUser`] if the
+ /// If the `cache` is enabled, returns a [`ModelError::InvalidUser`] if the
/// current user is not the author.
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over [`the limit`], containing the number of unicode code points
/// over the limit.
///
- /// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidUser
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
- /// [`the limit`]: ../utils/builder/struct.CreateMessage.html#method.content
+ /// [`ModelError::InvalidUser`]: enum.ModelError.html#variant.InvalidUser
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
+ /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content
pub fn edit<F>(&mut self, f: F) -> Result<()>
where F: FnOnce(CreateMessage) -> CreateMessage {
#[cfg(feature="cache")]
{
if self.author.id != CACHE.read().unwrap().user.id {
- return Err(Error::Client(ClientError::InvalidUser));
+ return Err(Error::Model(ModelError::InvalidUser));
}
}
@@ -174,7 +178,7 @@ impl Message {
let map = f(builder).0;
- match rest::edit_message(self.channel_id.0, self.id.0, &Value::Object(map)) {
+ match http::edit_message(self.channel_id.0, self.id.0, &Value::Object(map)) {
Ok(edited) => {
mem::replace(self, edited);
@@ -321,10 +325,10 @@ impl Message {
/// # Errors
///
/// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidPermissions`] if the current user does not have
+ /// [`ModelError::InvalidPermissions`] if the current user does not have
/// the required permissions.
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
pub fn pin(&self) -> Result<()> {
#[cfg(feature="cache")]
@@ -332,7 +336,7 @@ impl Message {
let req = permissions::MANAGE_MESSAGES;
if !utils::user_has_perms(self.channel_id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -346,10 +350,10 @@ impl Message {
/// # Errors
///
/// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidPermissions`] if the current user does not have
- /// the required [permissions].
+ /// [`ModelError::InvalidPermissions`] if the current user does not have the
+ /// required [permissions].
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [`Emoji`]: struct.Emoji.html
/// [Add Reactions]: permissions/constant.ADD_REACTIONS.html
/// [permissions]: permissions
@@ -359,11 +363,11 @@ impl Message {
let req = permissions::ADD_REACTIONS;
if !utils::user_has_perms(self.channel_id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
- rest::create_reaction(self.channel_id.0,
+ http::create_reaction(self.channel_id.0,
self.id.0,
&reaction_type.into())
}
@@ -380,19 +384,19 @@ impl Message {
/// # Errors
///
/// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidPermissions`] if the current user does not have
+ /// [`ModelError::InvalidPermissions`] if the current user does not have
/// the required permissions.
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
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)));
+ return Err(Error::Model(ModelError::MessageTooLong(length_over)));
}
#[cfg(feature="cache")]
@@ -400,7 +404,7 @@ impl Message {
let req = permissions::SEND_MESSAGES;
if !utils::user_has_perms(self.channel_id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -413,7 +417,7 @@ impl Message {
"tts": false,
});
- rest::send_message(self.channel_id.0, &map)
+ http::send_message(self.channel_id.0, &map)
}
/// Unpins the message from its channel.
@@ -423,10 +427,10 @@ impl Message {
/// # Errors
///
/// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidPermissions`] if the current user does not have
+ /// [`ModelError::InvalidPermissions`] if the current user does not have
/// the required permissions.
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
pub fn unpin(&self) -> Result<()> {
#[cfg(feature="cache")]
@@ -434,11 +438,11 @@ impl Message {
let req = permissions::MANAGE_MESSAGES;
if !utils::user_has_perms(self.channel_id, req)? {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
- rest::unpin_message(self.channel_id.0, self.id.0)
+ http::unpin_message(self.channel_id.0, self.id.0)
}
/// Alias of [`reaction_users`].
@@ -456,7 +460,7 @@ impl Message {
if let Some(content) = map.get("content") {
if let Value::String(ref content) = *content {
if let Some(length_over) = Message::overflow_length(content) {
- return Err(Error::Client(ClientError::MessageTooLong(length_over)));
+ return Err(Error::Model(ModelError::MessageTooLong(length_over)));
}
}
}
@@ -512,7 +516,7 @@ impl Message {
} else {
let overflow = total as u64 - constants::EMBED_MAX_LENGTH as u64;
- Err(Error::Client(ClientError::EmbedTooLarge(overflow)))
+ Err(Error::Model(ModelError::EmbedTooLarge(overflow)))
}
}
}
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs
index 33e4e9b..98e5f8d 100644
--- a/src/model/channel/mod.rs
+++ b/src/model/channel/mod.rs
@@ -22,7 +22,9 @@ use std::fmt::{Display, Formatter, Result as FmtResult};
use std::io::Read;
use super::utils::deserialize_u64;
use ::model::*;
-use ::utils::builder::{CreateMessage, GetMessages};
+
+#[cfg(feature="model")]
+use ::builder::{CreateMessage, GetMessages};
/// A container for any channel.
#[derive(Clone, Debug)]
@@ -42,6 +44,7 @@ pub enum Channel {
Private(Arc<RwLock<PrivateChannel>>),
}
+#[cfg(feature="model")]
impl Channel {
/// React to a [`Message`] with a custom [`Emoji`] or unicode character.
///
@@ -151,14 +154,14 @@ impl Channel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the [`the limit`], containing the number of unicode code points
/// over the limit.
///
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [`Message`]: struct.Message.html
- /// [`the limit`]: ../utils/builder/struct.CreateMessage.html#method.content
+ /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content
#[inline]
pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> {
@@ -170,6 +173,7 @@ impl Channel {
/// Refer to [`utils::is_nsfw`] for more details.
///
/// [`utils::is_nsfw`]: ../utils/fn.is_nsfw.html
+ #[cfg(feature="utils")]
#[inline]
pub fn is_nsfw(&self) -> bool {
match *self {
@@ -255,12 +259,12 @@ impl Channel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
- /// [`ChannelId`]: ../model/struct.ChannelId.html
- /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
+ /// [`ChannelId`]: struct.ChannelId.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
#[inline]
pub fn say(&self, content: &str) -> Result<Message> {
self.id().say(content)
@@ -278,11 +282,11 @@ impl Channel {
/// # Errors
///
/// If the content of the message is over the above limit, then a
- /// [`ClientError::MessageTooLong`] will be returned, containing the number
+ /// [`ModelError::MessageTooLong`] will be returned, containing the number
/// of unicode code points over the limit.
///
/// [`ChannelId::send_file`]: struct.ChannelId.html#method.send_file
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_file<F, R>(&self, file: R, filename: &str, f: F) -> Result<Message>
@@ -301,13 +305,13 @@ impl Channel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
/// [`Channel`]: enum.Channel.html
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
#[inline]
pub fn send_message<F>(&self, f: F) -> Result<Message>
@@ -384,6 +388,7 @@ impl<'de> Deserialize<'de> for Channel {
}
}
+#[cfg(feature="model")]
impl Display for Channel {
/// Formats the channel into a "mentioned" string.
///
@@ -487,9 +492,9 @@ impl<'de> Deserialize<'de> for PermissionOverwrite {
/// The type of edit being made to a Channel's permissions.
///
-/// This is for use with methods such as `Context::create_permission`.
+/// This is for use with methods such as `GuildChannel::create_permission`.
///
-/// [`Context::create_permission`]: ../client/
+/// [`GuildChannel::create_permission`]: struct.GuildChannel.html#method.create_permission
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum PermissionOverwriteType {
/// A member which is having its permission overwrites edited.
diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs
index 910daa2..9e2aec1 100644
--- a/src/model/channel/private_channel.rs
+++ b/src/model/channel/private_channel.rs
@@ -2,7 +2,9 @@ use std::fmt::{Display, Formatter, Result as FmtResult};
use std::io::Read;
use super::deserialize_single_recipient;
use ::model::*;
-use ::utils::builder::{CreateMessage, GetMessages};
+
+#[cfg(feature="model")]
+use ::builder::{CreateMessage, GetMessages};
/// A Direct Message text channel with another user.
#[derive(Clone, Debug, Deserialize)]
@@ -29,6 +31,7 @@ pub struct PrivateChannel {
pub recipient: Arc<RwLock<User>>,
}
+#[cfg(feature="model")]
impl PrivateChannel {
/// Broadcasts that the current user is typing to the recipient.
pub fn broadcast_typing(&self) -> Result<()> {
@@ -114,14 +117,14 @@ impl PrivateChannel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the [`the limit`], containing the number of unicode code points
/// over the limit.
///
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [`Message`]: struct.Message.html
- /// [`the limit`]: ../utils/builder/struct.CreateMessage.html#method.content
+ /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content
#[inline]
pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> {
@@ -206,12 +209,12 @@ impl PrivateChannel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
/// [`ChannelId`]: ../model/struct.ChannelId.html
- /// [`ClientError::MessageTooLong`]: enum.ClientError.html#variant.MessageTooLong
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
#[inline]
pub fn say(&self, content: &str) -> Result<Message> {
self.id.say(content)
@@ -229,11 +232,11 @@ impl PrivateChannel {
/// # Errors
///
/// If the content of the message is over the above limit, then a
- /// [`ClientError::MessageTooLong`] will be returned, containing the number
+ /// [`ModelError::MessageTooLong`] will be returned, containing the number
/// of unicode code points over the limit.
///
/// [`ChannelId::send_file`]: struct.ChannelId.html#method.send_file
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
/// [Attach Files]: permissions/constant.ATTACH_FILES.html
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_file<F, R>(&self, file: R, filename: &str, f: F) -> Result<Message>
@@ -248,12 +251,12 @@ impl PrivateChannel {
///
/// # Errors
///
- /// Returns a [`ClientError::MessageTooLong`] if the content of the message
+ /// Returns a [`ModelError::MessageTooLong`] if the content of the message
/// is over the above limit, containing the number of unicode code points
/// over the limit.
///
- /// [`ClientError::MessageTooLong`]: ../client/enum.ClientError.html#variant.MessageTooLong
- /// [`CreateMessage`]: ../utils/builder/struct.CreateMessage.html
+ /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong
+ /// [`CreateMessage`]: ../builder/struct.CreateMessage.html
/// [`Message`]: struct.Message.html
#[inline]
pub fn send_message<F: FnOnce(CreateMessage) -> CreateMessage>(&self, f: F) -> Result<Message> {
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs
index 9c3618d..132af7b 100644
--- a/src/model/channel/reaction.rs
+++ b/src/model/channel/reaction.rs
@@ -1,12 +1,14 @@
use serde::de::{Deserialize, Error as DeError, MapAccess, Visitor};
use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite};
-use ::client::rest;
use ::internal::prelude::*;
use ::model::*;
#[cfg(feature="cache")]
-use ::client::CACHE;
+use ::CACHE;
+#[cfg(feature="model")]
+use ::http;
+#[cfg(feature="model")]
impl Reaction {
/// Deletes the reaction, but only if the current user is the user who made
/// the reaction or has permission to.
@@ -17,10 +19,10 @@ impl Reaction {
/// # Errors
///
/// If the `cache` is enabled, then returns a
- /// [`ClientError::InvalidPermissions`] if the current user does not have
+ /// [`ModelError::InvalidPermissions`] if the current user does not have
/// the required [permissions].
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
/// [permissions]: permissions
pub fn delete(&self) -> Result<()> {
@@ -41,7 +43,7 @@ impl Reaction {
let req = permissions::MANAGE_MESSAGES;
if !utils::user_has_perms(self.channel_id, req).unwrap_or(true) {
- return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
}
@@ -50,7 +52,7 @@ impl Reaction {
Some(self.user_id.0)
}};
- rest::delete_reaction(self.channel_id.0,
+ http::delete_reaction(self.channel_id.0,
self.message_id.0,
user_id,
&self.emoji)
@@ -70,10 +72,10 @@ impl Reaction {
///
/// # Errors
///
- /// Returns a [`ClientError::InvalidPermissions`] if the current user does
+ /// Returns a [`ModelError::InvalidPermissions`] if the current user does
/// not have the required [permissions].
///
- /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`ModelError::InvalidPermissions`]: enum.ModelError.html#variant.InvalidPermissions
/// [`Emoji`]: struct.Emoji.html
/// [`Message`]: struct.Message.html
/// [`User`]: struct.User.html
@@ -86,7 +88,7 @@ impl Reaction {
-> Result<Vec<User>>
where R: Into<ReactionType>,
U: Into<UserId> {
- rest::get_reaction_users(self.channel_id.0,
+ http::get_reaction_users(self.channel_id.0,
self.message_id.0,
&reaction_type.into(),
limit.unwrap_or(50),
@@ -201,6 +203,7 @@ impl<'de> Deserialize<'de> for ReactionType {
}
}
+#[cfg(any(feature="model", feature="http"))]
impl ReactionType {
/// Creates a data-esque display of the type. This is not very useful for
/// displaying, as the primary client can not render it, but can be useful