aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-04-05 08:14:43 -0700
committerZeyla Hellyer <[email protected]>2017-04-05 08:55:01 -0700
commitd9118c081742d6654dc0a4f60228a7a212ca436e (patch)
tree003f49f54769314c1111e942d77f57513406fb5e /src/model
parentAdd a sample bot structure example (diff)
downloadserenity-d9118c081742d6654dc0a4f60228a7a212ca436e.tar.xz
serenity-d9118c081742d6654dc0a4f60228a7a212ca436e.zip
Remove selfbot support
While selfbots have always been "roughly tolerated", lately they have been tolerated to less of a degree. The simple answer is to no longer support selfbots in any form. This is done for a few of reasons: 1) in anticipation of selfbots no longer being tolerated; 2) there are few reasons why one should make a selfbot in Rust and not a scripting language; 3) there are alternatives (i.e. discord-rs) that still support userbots. Selfbots are simply not a goal of the maintainer of serenity. Upgrade path: Don't use selfbots with serenity. Use discord-rs instead. The following has been removed: Enums: - `RelationshipType` Structs: - `FriendSourceFlags` - `ReadState` - `Relationship` - `SearchResult` - `SuggestionReason` - `Tutorial` - `UserConnection` - `UserGuildSettings` - `UserSettings` Removed the following fields: - `CurrentUser::mobile` - Ready::{ analytics_token, experiments, friend_suggestion_count, notes, read_state, relationships, tutorial, user_guild_settings, user_settings, } Removed the following methods: - `Client::login_user` Deprecated `Client::login_bot` in favour of `Client::login`. Removed `client::LoginType`. The following no longer take a `login_type` parameter: - `Context::new` - `Shard::new` `Shard::sync_guilds` has been removed. The `client::Error::{InvalidOperationAsBot, InvalidOperationAsUser}` variants have been removed. The following event handlers on `Client` have been removed: - `on_friend_suggestion_create` - `on_friend_suggestion_delete` - `on_relationship_add` - `on_relationship_remove` - `on_user_guild_settings_update` - `on_note_update` - `on_user_settings_update` The following `client::rest` functions have been removed: - `ack_message` - `edit_note` - `get_user_connections` - `search_channel_messages` - `search_guild_messages` The following `client::rest::ratelimiting::Route` variants have been removed: - `ChannelsIdMessagesSearch` - `GuildsIdMessagesSearch` - `UsersMeConnections` The following fields on `ext::cache::Cache` have been removed: - `guild_settings` - `relationships` - `settings` while the following methods have also been removed: - `update_with_relationship_add` - `update_with_relationship_remove` - `update_with_user_guild_settings_update` - `update_with_user_note_update` - `update_with_user_settings_update` The following methods have been removed across models: - `ChannelId::{ack, search}` - `Channel::{ack, search}` - `Group::{ack, search}` - `GuildChannel::{ack, search}` - `GuildId::{search, search_channels}` - `Guild::{search, search_channels}` - `Message::ack` - `PartialGuild::{search, search_channels}` - `PrivateChannel::{ack, search}` - `UserId::{delete_note, edit_note}` - `User::{delete_note, edit_note}` The following events in `model::events` have been removed: - `FriendSuggestionCreateEvent` - `FriendSuggestionDeleteEvent` - `MessageAckEvent` - `RelationshipAddEvent` - `RelationshipRemoveEvent` - `UserGuildSettingsUpdateEvent` - `UserNoteUpdateEvent` - `UserSettingsUpdateEvent` Consequently, the following variants on `model::event::Event` have been removed: - `FriendSuggestionCreate` - `FriendSuggestionDelete` - `MessageAdd` - `RelationshipAdd` - `RelationshipRemove` - `UserGuildSettingUpdate` - `UserNoteUpdate` - `UserSettingsUpdate` The `utils::builder::Search` search builder has been removed.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel/attachment.rs2
-rw-r--r--src/model/channel/channel_id.rs39
-rw-r--r--src/model/channel/group.rs50
-rw-r--r--src/model/channel/guild_channel.rs58
-rw-r--r--src/model/channel/message.rs31
-rw-r--r--src/model/channel/mod.rs57
-rw-r--r--src/model/channel/private_channel.rs55
-rw-r--r--src/model/channel/reaction.rs5
-rw-r--r--src/model/event.rs183
-rw-r--r--src/model/guild/emoji.rs11
-rw-r--r--src/model/guild/guild_id.rs48
-rw-r--r--src/model/guild/member.rs6
-rw-r--r--src/model/guild/mod.rs79
-rw-r--r--src/model/guild/partial_guild.rs75
-rw-r--r--src/model/guild/role.rs6
-rw-r--r--src/model/user.rs109
-rw-r--r--src/model/utils.rs100
17 files changed, 54 insertions, 860 deletions
diff --git a/src/model/channel/attachment.rs b/src/model/channel/attachment.rs
index 387edaf..b6ce53d 100644
--- a/src/model/channel/attachment.rs
+++ b/src/model/channel/attachment.rs
@@ -28,7 +28,7 @@ impl Attachment {
/// use std::path::Path;
///
/// let token = env::var("DISCORD_TOKEN").expect("token in environment");
- /// let mut client = Client::login_bot(&token);
+ /// let mut client = Client::login(&token);
///
/// client.on_message(|_, message| {
/// for attachment in message.attachments {
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index 2d09367..7a2fb3a 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -1,24 +1,14 @@
use serde_json::builder::ObjectBuilder;
use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite};
use std::io::Read;
-use ::client::{CACHE, rest};
+use ::client::rest;
use ::model::*;
-use ::utils::builder::{CreateMessage, EditChannel, GetMessages, Search};
+use ::utils::builder::{CreateMessage, EditChannel, GetMessages};
-impl ChannelId {
- /// Marks a [`Channel`] as being read up to a certain [`Message`].
- ///
- /// Refer to the documentation for [`rest::ack_message`] for more
- /// information.
- ///
- /// [`Channel`]: enum.Channel.html
- /// [`Message`]: struct.Message.html
- /// [`rest::ack_message`]: rest/fn.ack_message.html
- #[inline]
- pub fn ack<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- rest::ack_message(self.0, message_id.into().0)
- }
+#[cfg(feature="cache")]
+use ::client::CACHE;
+impl ChannelId {
/// Broadcasts that the current user is typing to a channel for the next 5
/// seconds.
///
@@ -358,25 +348,6 @@ impl ChannelId {
self.send_message(|m| m.content(content))
}
- /// Searches the channel's messages by providing query parameters via the
- /// search builder.
- ///
- /// Refer to the documentation for the [`Search`] builder for restrictions
- /// and defaults parameters, as well as potentially advanced usage.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Examples
- ///
- /// Refer to the [`Search`] builder's documentation for examples,
- /// specifically the section on [searching a channel][search channel].
- ///
- /// [`Search`]: ../utils/builder/struct.Search.html
- #[inline]
- pub fn search<F: FnOnce(Search) -> Search>(&self, f: F) -> Result<SearchResult> {
- rest::search_channel_messages(self.0, f(Search::default()).0)
- }
-
/// Sends a file along with optional message contents. The filename _must_
/// be specified.
///
diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs
index 9d3335f..f287e9a 100644
--- a/src/model/channel/group.rs
+++ b/src/model/channel/group.rs
@@ -1,36 +1,11 @@
use std::borrow::Cow;
use std::fmt::Write as FmtWrite;
use std::io::Read;
-use ::client::{CACHE, rest};
+use ::client::rest;
use ::model::*;
-use ::utils::builder::{CreateMessage, GetMessages, Search};
+use ::utils::builder::{CreateMessage, GetMessages};
impl Group {
- /// Marks the group as being read up to a certain [`Message`].
- ///
- /// Refer to the documentation for [`rest::ack_message`] for more
- /// information.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot
- /// user.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsUser
- /// [`Message`]: struct.Message.html
- /// [`rest::ack_message`]: ../client/rest/fn.ack_message.html
- pub fn ack<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.channel_id.ack(message_id)
- }
-
/// Adds the given user to the group. If the user is already in the group,
/// then nothing is done.
///
@@ -257,27 +232,6 @@ impl Group {
self.channel_id.say(content)
}
- /// Performs a search request to the API for the group's channel's
- /// [`Message`]s.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- #[inline]
- pub fn search<F: FnOnce(Search) -> Search>(&self, f: F) -> Result<SearchResult> {
- self.channel_id.search(f)
- }
-
/// Sends a file along with optional message contents. The filename _must_
/// be specified.
///
diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs
index 677e77b..e4a84c7 100644
--- a/src/model/channel/guild_channel.rs
+++ b/src/model/channel/guild_channel.rs
@@ -2,37 +2,15 @@ use serde_json::builder::ObjectBuilder;
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::io::Read;
use std::mem;
-use ::client::{CACHE, rest};
+use ::client::rest;
use ::internal::prelude::*;
use ::model::*;
-use ::utils::builder::{CreateInvite, CreateMessage, EditChannel, GetMessages, Search};
+use ::utils::builder::{CreateInvite, CreateMessage, EditChannel, GetMessages};
-impl GuildChannel {
- /// Marks the channel as being read up to a certain [`Message`].
- ///
- /// Refer to the documentation for [`rest::ack_message`] for more
- /// information.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot
- /// user.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsUser
- /// [`Message`]: struct.Message.html
- /// [`rest::ack_message`]: ../client/rest/fn.ack_message.html
- pub fn ack<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- rest::ack_message(self.id.0, message_id.into().0)
- }
+#[cfg(feature="cache")]
+use ::client::CACHE;
+impl GuildChannel {
/// Broadcasts to the channel that the current user is typing.
///
/// For bots, this is a good indicator for long-running commands.
@@ -402,32 +380,6 @@ impl GuildChannel {
self.id.say(content)
}
- /// Performs a search request for the channel's [`Message`]s.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- pub fn search<F: FnOnce(Search) -> Search>(&self, f: F) -> Result<SearchResult> {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id.search(f)
- }
-
/// Sends a file along with optional message contents. The filename _must_
/// be specified.
///
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs
index 84d726d..709ce9a 100644
--- a/src/model/channel/message.rs
+++ b/src/model/channel/message.rs
@@ -1,37 +1,14 @@
use serde_json::builder::ObjectBuilder;
use std::mem;
use ::constants;
-use ::client::{CACHE, rest};
+use ::client::rest;
use ::model::*;
use ::utils::builder::{CreateEmbed, CreateMessage};
-impl Message {
- /// Marks the [`Channel`] as being read up to the message.
- ///
- /// Refer to the documentation for [`rest::ack_message`] for more
- /// information.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot
- /// user.
- ///
- /// [`Channel`]: enum.Channel.html
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsUser
- /// [`Message`]: struct.Message.html
- /// [`rest::ack_message`]: ../client/rest/fn.ack_message.html
- pub fn ack<M: Into<MessageId>>(&self) -> Result<()> {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.channel_id.ack(self.id)
- }
+#[cfg(feature="cache")]
+use ::client::CACHE;
+impl Message {
/// Deletes the message.
///
/// **Note**: The logged in user must either be the author of the message or
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs
index ff12084..3ea765a 100644
--- a/src/model/channel/mod.rs
+++ b/src/model/channel/mod.rs
@@ -18,37 +18,10 @@ pub use self::reaction::*;
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::io::Read;
-use ::client::CACHE;
use ::model::*;
-use ::utils::builder::{CreateMessage, GetMessages, Search};
+use ::utils::builder::{CreateMessage, GetMessages};
impl Channel {
- /// Marks the channel as being read up to a certain [`Message`].
- ///
- /// Refer to the documentation for [`rest::ack_message`] for more
- /// information.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot
- /// user.
- ///
- /// [`Channel`]: enum.Channel.html
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsUser
- /// [`Message`]: struct.Message.html
- /// [`rest::ack_message`]: ../client/rest/fn.ack_message.html
- pub fn ack<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id().ack(message_id)
- }
-
/// React to a [`Message`] with a custom [`Emoji`] or unicode character.
///
/// [`Message::react`] may be a more suited method of reacting in most
@@ -273,34 +246,6 @@ impl Channel {
self.id().say(content)
}
- /// Performs a search request to the API for the inner channel's
- /// [`Message`]s.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- pub fn search<F>(&self, f: F) -> Result<SearchResult>
- where F: FnOnce(Search) -> Search {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id().search(f)
- }
-
/// Sends a file along with optional message contents. The filename _must_
/// be specified.
///
diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs
index ae64d7e..8ce520c 100644
--- a/src/model/channel/private_channel.rs
+++ b/src/model/channel/private_channel.rs
@@ -1,35 +1,9 @@
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::io::Read;
-use ::client::CACHE;
use ::model::*;
-use ::utils::builder::{CreateMessage, GetMessages, Search};
+use ::utils::builder::{CreateMessage, GetMessages};
impl PrivateChannel {
- /// Marks the channel as being read up to a certain [`Message`].
- ///
- /// Refer to the documentation for [`rest::ack_message`] for more
- /// information.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot
- /// user.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsUser
- /// [`Message`]: struct.Message.html
- /// [`rest::ack_message`]: ../client/rest/fn.ack_message.html
- pub fn ack<M: Into<MessageId>>(&self, message_id: M) -> Result<()> {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id.ack(message_id)
- }
-
/// Broadcasts that the current user is typing to the recipient.
pub fn broadcast_typing(&self) -> Result<()> {
self.id.broadcast_typing()
@@ -219,33 +193,6 @@ impl PrivateChannel {
self.id.say(content)
}
- /// Performs a search request to the API for the channel's [`Message`]s.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- pub fn search<F>(&self, f: F) -> Result<SearchResult>
- where F: FnOnce(Search) -> Search {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id.search(f)
- }
-
/// Sends a file along with optional message contents. The filename _must_
/// be specified.
///
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs
index eaeb2cc..aa4f339 100644
--- a/src/model/channel/reaction.rs
+++ b/src/model/channel/reaction.rs
@@ -1,8 +1,11 @@
use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite};
-use ::client::{CACHE, rest};
+use ::client::rest;
use ::internal::prelude::*;
use ::model::*;
+#[cfg(feature="cache")]
+use ::client::CACHE;
+
impl Reaction {
/// Deletes the reaction, but only if the current user is the user who made
/// the reaction or has permission to.
diff --git a/src/model/event.rs b/src/model/event.rs
index d9e6523..a39fa2a 100644
--- a/src/model/event.rs
+++ b/src/model/event.rs
@@ -241,38 +241,6 @@ impl ChannelUpdateEvent {
}
#[derive(Clone, Debug)]
-pub struct FriendSuggestionCreateEvent {
- pub reasons: Vec<SuggestionReason>,
- pub suggested_user: User,
-}
-
-impl FriendSuggestionCreateEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(FriendSuggestionCreateEvent {
- reasons: decode_array(remove(&mut map, "reasons")?, SuggestionReason::decode)?,
- suggested_user: remove(&mut map, "suggested_user").and_then(User::decode)?,
- })
- }
-}
-
-#[derive(Clone, Copy, Debug)]
-pub struct FriendSuggestionDeleteEvent {
- pub suggested_user_id: UserId,
-}
-
-impl FriendSuggestionDeleteEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(FriendSuggestionDeleteEvent {
- suggested_user_id: remove(&mut map, "suggested_user_id").and_then(UserId::decode)?,
- })
- }
-}
-
-#[derive(Clone, Debug)]
pub struct GuildBanAddEvent {
pub guild_id: GuildId,
pub user: User,
@@ -546,24 +514,6 @@ impl GuildUpdateEvent {
}
}
-#[derive(Clone, Copy, Debug)]
-pub struct MessageAckEvent {
- pub channel_id: ChannelId,
- /// May be `None` if a private channel with no messages has closed.
- pub message_id: Option<MessageId>,
-}
-
-impl MessageAckEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(MessageAckEvent {
- channel_id: remove(&mut map, "channel_id").and_then(ChannelId::decode)?,
- message_id: opt(&mut map, "message_id", MessageId::decode)?,
- })
- }
-}
-
#[derive(Clone, Debug)]
pub struct MessageCreateEvent {
pub message: Message,
@@ -757,38 +707,6 @@ impl ReadyEvent {
}
#[derive(Clone, Debug)]
-pub struct RelationshipAddEvent {
- pub relationship: Relationship,
-}
-
-impl RelationshipAddEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(map: Map) -> Result<Self> {
- Ok(RelationshipAddEvent {
- relationship: Relationship::decode(Value::Object(map))?,
- })
- }
-}
-
-#[derive(Clone, Copy, Debug)]
-pub struct RelationshipRemoveEvent {
- pub kind: RelationshipType,
- pub user_id: UserId,
-}
-
-impl RelationshipRemoveEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(RelationshipRemoveEvent {
- kind: remove(&mut map, "type").and_then(RelationshipType::decode)?,
- user_id: remove(&mut map, "id").and_then(UserId::decode)?,
- })
- }
-}
-
-#[derive(Clone, Debug)]
pub struct ResumedEvent {
pub trace: Vec<Option<String>>,
}
@@ -829,38 +747,6 @@ pub struct UnknownEvent {
}
#[derive(Clone, Debug)]
-pub struct UserGuildSettingsUpdateEvent {
- pub settings: UserGuildSettings,
-}
-
-impl UserGuildSettingsUpdateEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(map: Map) -> Result<Self> {
- Ok(UserGuildSettingsUpdateEvent {
- settings: UserGuildSettings::decode(Value::Object(map))?,
- })
- }
-}
-
-#[derive(Clone, Debug)]
-pub struct UserNoteUpdateEvent {
- pub note: String,
- pub user_id: UserId,
-}
-
-impl UserNoteUpdateEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(UserNoteUpdateEvent {
- note: remove(&mut map, "note").and_then(into_string)?,
- user_id: remove(&mut map, "id").and_then(UserId::decode)?,
- })
- }
-}
-
-#[derive(Clone, Debug)]
pub struct UserUpdateEvent {
pub current_user: CurrentUser,
}
@@ -876,41 +762,6 @@ impl UserUpdateEvent {
}
#[derive(Clone, Debug)]
-pub struct UserSettingsUpdateEvent {
- pub enable_tts_command: Option<bool>,
- pub inline_attachment_media: Option<bool>,
- pub inline_embed_media: Option<bool>,
- pub locale: Option<String>,
- pub message_display_compact: Option<bool>,
- pub render_embeds: Option<bool>,
- pub show_current_game: Option<bool>,
- pub theme: Option<String>,
- pub convert_emoticons: Option<bool>,
- pub friend_source_flags: Option<FriendSourceFlags>,
- pub status: Option<OnlineStatus>,
-}
-
-impl UserSettingsUpdateEvent {
- #[doc(hidden)]
- #[inline]
- pub fn decode(mut map: Map) -> Result<Self> {
- Ok(UserSettingsUpdateEvent {
- enable_tts_command: remove(&mut map, "enable_tts_command").ok().and_then(|v| v.as_bool()),
- inline_attachment_media: remove(&mut map, "inline_attachment_media").ok().and_then(|v| v.as_bool()),
- inline_embed_media: remove(&mut map, "inline_embed_media").ok().and_then(|v| v.as_bool()),
- locale: opt(&mut map, "locale", into_string)?,
- message_display_compact: remove(&mut map, "message_display_compact").ok().and_then(|v| v.as_bool()),
- render_embeds: remove(&mut map, "render_embeds").ok().and_then(|v| v.as_bool()),
- show_current_game: remove(&mut map, "show_current_game").ok().and_then(|v| v.as_bool()),
- theme: opt(&mut map, "theme", into_string)?,
- convert_emoticons: remove(&mut map, "convert_emoticons").ok().and_then(|v| v.as_bool()),
- friend_source_flags: opt(&mut map, "friend_source_flags", FriendSourceFlags::decode)?,
- status: opt(&mut map, "status", OnlineStatus::decode_str)?,
- })
- }
-}
-
-#[derive(Clone, Debug)]
pub struct VoiceServerUpdateEvent {
pub channel_id: Option<ChannelId>,
pub endpoint: Option<String>,
@@ -1080,22 +931,6 @@ pub enum Event {
/// [`Client::on_channel_update`]: ../../client/struct.Client.html#on_channel_update
/// [`User`]: ../struct.User.html
ChannelUpdate(ChannelUpdateEvent),
- /// When a suggestion for a friend is created, due to a connection like
- /// [Skype][`Connection::Skype`].
- ///
- /// Fires the [`on_friend_suggestion_create`] event.
- ///
- /// [`Connection::Skype`]: enum.Connection.html#variant.Skype
- /// [`on_friend_suggestion_delete`]: ../../client/struct.Client.html#on_friend_suggestion_create
- FriendSuggestionCreate(FriendSuggestionCreateEvent),
- /// When a suggestion for a friend is removed, due to a connection like
- /// [Skype][`Connection::Skype`].
- ///
- /// Fires the [`on_friend_suggestion_delete`] event.
- ///
- /// [`Connection::Skype`]: enum.Connection.html#variant.Skype
- /// [`on_friend_suggestion_create`]: ../../client/struct.Client.html#on_friend_suggestion_delete
- FriendSuggestionDelete(FriendSuggestionDeleteEvent),
GuildBanAdd(GuildBanAddEvent),
GuildBanRemove(GuildBanRemoveEvent),
GuildCreate(GuildCreateEvent),
@@ -1114,8 +949,6 @@ pub enum Event {
/// When a guild is unavailable, such as due to a Discord server outage.
GuildUnavailable(GuildUnavailableEvent),
GuildUpdate(GuildUpdateEvent),
- /// Another logged-in device acknowledged this message
- MessageAck(MessageAckEvent),
MessageCreate(MessageCreateEvent),
MessageDelete(MessageDeleteEvent),
MessageDeleteBulk(MessageDeleteBulkEvent),
@@ -1149,20 +982,12 @@ pub enum Event {
///
/// May also be received at a later time in the event of a reconnect.
Ready(ReadyEvent),
- RelationshipAdd(RelationshipAddEvent),
- RelationshipRemove(RelationshipRemoveEvent),
/// The connection has successfully resumed after a disconnect.
Resumed(ResumedEvent),
/// A user is typing; considered to last 5 seconds
TypingStart(TypingStartEvent),
- /// Update to the logged-in user's guild-specific notification settings
- UserGuildSettingsUpdate(UserGuildSettingsUpdateEvent),
- /// Update to a note that the logged-in user has set for another user.
- UserNoteUpdate(UserNoteUpdateEvent),
/// Update to the logged-in user's information
UserUpdate(UserUpdateEvent),
- /// Update to the logged-in user's preferences or client settings
- UserSettingsUpdate(UserSettingsUpdateEvent),
/// A member's voice state has changed
VoiceStateUpdate(VoiceStateUpdateEvent),
/// Voice server information is available
@@ -1196,8 +1021,6 @@ impl Event {
"CHANNEL_RECIPIENT_ADD" => Event::ChannelRecipientAdd(ChannelRecipientAddEvent::decode(value)?),
"CHANNEL_RECIPIENT_REMOVE" => Event::ChannelRecipientRemove(ChannelRecipientRemoveEvent::decode(value)?),
"CHANNEL_UPDATE" => Event::ChannelUpdate(ChannelUpdateEvent::decode(value)?),
- "FRIEND_SUGGESTION_CREATE" => Event::FriendSuggestionCreate(FriendSuggestionCreateEvent::decode(value)?),
- "FRIEND_SUGGESTION_DELETE" => Event::FriendSuggestionDelete(FriendSuggestionDeleteEvent::decode(value)?),
"GUILD_BAN_ADD" => Event::GuildBanAdd(GuildBanAddEvent::decode(value)?),
"GUILD_BAN_REMOVE" => Event::GuildBanRemove(GuildBanRemoveEvent::decode(value)?),
"GUILD_CREATE" => {
@@ -1225,7 +1048,6 @@ impl Event {
"GUILD_ROLE_UPDATE" => Event::GuildRoleUpdate(GuildRoleUpdateEvent::decode(value)?),
"GUILD_SYNC" => Event::GuildSync(GuildSyncEvent::decode(value)?),
"GUILD_UPDATE" => Event::GuildUpdate(GuildUpdateEvent::decode(value)?),
- "MESSAGE_ACK" => Event::MessageAck(MessageAckEvent::decode(value)?),
"MESSAGE_CREATE" => Event::MessageCreate(MessageCreateEvent::decode(value)?),
"MESSAGE_DELETE" => Event::MessageDelete(MessageDeleteEvent::decode(value)?),
"MESSAGE_DELETE_BULK" => Event::MessageDeleteBulk(MessageDeleteBulkEvent::decode(value)?),
@@ -1234,14 +1056,9 @@ impl Event {
"MESSAGE_REACTION_REMOVE_ALL" => Event::ReactionRemoveAll(ReactionRemoveAllEvent::decode(value)?),
"MESSAGE_UPDATE" => Event::MessageUpdate(MessageUpdateEvent::decode(value)?),
"PRESENCE_UPDATE" => Event::PresenceUpdate(PresenceUpdateEvent::decode(value)?),
- "RELATIONSHIP_ADD" => Event::RelationshipAdd(RelationshipAddEvent::decode(value)?),
- "RELATIONSHIP_REMOVE" => Event::RelationshipRemove(RelationshipRemoveEvent::decode(value)?),
"READY" => Event::Ready(ReadyEvent::decode(value)?),
"RESUMED" => Event::Resumed(ResumedEvent::decode(value)?),
"TYPING_START" => Event::TypingStart(TypingStartEvent::decode(value)?),
- "USER_GUILD_SETTINGS_UPDATE" => Event::UserGuildSettingsUpdate(UserGuildSettingsUpdateEvent::decode(value)?),
- "USER_NOTE_UPDATE" => Event::UserNoteUpdate(UserNoteUpdateEvent::decode(value)?),
- "USER_SETTINGS_UPDATE" => Event::UserSettingsUpdate(UserSettingsUpdateEvent::decode(value)?),
"USER_UPDATE" => Event::UserUpdate(UserUpdateEvent::decode(value)?),
"VOICE_SERVER_UPDATE" => Event::VoiceServerUpdate(VoiceServerUpdateEvent::decode(value)?),
"VOICE_STATE_UPDATE" => Event::VoiceStateUpdate(VoiceStateUpdateEvent::decode(value)?),
diff --git a/src/model/guild/emoji.rs b/src/model/guild/emoji.rs
index 43e57a2..0bb0f40 100644
--- a/src/model/guild/emoji.rs
+++ b/src/model/guild/emoji.rs
@@ -1,9 +1,16 @@
-use serde_json::builder::ObjectBuilder;
use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite};
+use ::model::{Emoji, EmojiId};
+
+#[cfg(feature="cache")]
+use serde_json::builder::ObjectBuilder;
+#[cfg(feature="cache")]
use std::mem;
+#[cfg(feature="cache")]
use ::client::{CACHE, rest};
-use ::model::{Emoji, EmojiId, GuildId};
+#[cfg(feature="cache")]
use ::internal::prelude::*;
+#[cfg(feature="cache")]
+use ::model::GuildId;
impl Emoji {
/// Deletes the emoji.
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs
index 83dc19a..d568360 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -1,9 +1,12 @@
use serde_json::builder::ObjectBuilder;
use std::fmt::{Display, Formatter, Result as FmtResult};
-use ::client::{CACHE, rest};
+use ::client::rest;
use ::internal::prelude::*;
use ::model::*;
-use ::utils::builder::{EditGuild, EditMember, EditRole, Search};
+use ::utils::builder::{EditGuild, EditMember, EditRole};
+
+#[cfg(feature="cache")]
+use ::client::CACHE;
impl GuildId {
/// Converts the guild Id into the default channel's Id.
@@ -413,47 +416,6 @@ impl GuildId {
rest::edit_member(self.0, user_id.into().0, &map)
}
- /// Performs a search request to the API for the guild's [`Message`]s.
- ///
- /// This will search all of the guild's [`Channel`]s at once, that you have
- /// the [Read Message History] permission to. Use [`search_channels`] to
- /// specify a list of [channel][`GuildChannel`]s to search, where all other
- /// channels will be excluded.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// [`Channel`]: enum.Channel.html
- /// [`GuildChannel`]: struct.GuildChannel.html
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- /// [`search_channels`]: #method.search_channels
- /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
- #[inline]
- pub fn search<F: FnOnce(Search) -> Search>(&self, f: F) -> Result<SearchResult> {
- rest::search_guild_messages(self.0, &[], f(Search::default()).0)
- }
-
- /// Performs a search request to the API for the guild's [`Message`]s in
- /// given channels.
- ///
- /// Refer to [`Guild::search_channels`] for more information.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// [`Guild::search_channels`]: struct.Guild.html#method.search_channels
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- pub fn search_channels<F>(&self, channel_ids: &[ChannelId], f: F)
- -> Result<SearchResult> where F: FnOnce(Search) -> Search {
- let ids = channel_ids.iter().map(|x| x.0).collect::<Vec<u64>>();
-
- rest::search_guild_messages(self.0, &ids, f(Search::default()).0)
- }
-
/// Starts an integration sync for the given integration Id.
///
/// Requires the [Manage Guild] permission.
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index 67d9dae..8fc53e1 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -1,9 +1,13 @@
use std::borrow::Cow;
use std::fmt::{Display, Formatter, Result as FmtResult};
-use ::client::{CACHE, rest};
use ::internal::prelude::*;
use ::model::*;
+
+#[cfg(feature="cache")]
+use ::client::{CACHE, rest};
+#[cfg(feature="cache")]
use ::utils::builder::EditMember;
+#[cfg(feature="cache")]
use ::utils::Colour;
impl Member {
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index 0b008c8..8b21ac7 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -1,8 +1,11 @@
use serde_json::builder::ObjectBuilder;
-use ::client::{CACHE, rest};
+use ::client::rest;
use ::constants::LARGE_THRESHOLD;
use ::model::*;
-use ::utils::builder::{EditGuild, EditMember, EditRole, Search};
+use ::utils::builder::{EditGuild, EditMember, EditRole};
+
+#[cfg(feature="cache")]
+use ::client::CACHE;
mod emoji;
mod guild_id;
@@ -831,78 +834,6 @@ impl Guild {
permissions
}
- /// Performs a search request to the API for the guild's [`Message`]s.
- ///
- /// This will search all of the guild's [`Channel`]s at once, that you have
- /// the [Read Message History] permission to. Use [`search_channels`] to
- /// specify a list of [channel][`GuildChannel`]s to search, where all other
- /// channels will be excluded.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`Channel`]: enum.Channel.html
- /// [`GuildChannel`]: struct.GuildChannel.html
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- /// [`search_channels`]: #method.search_channels
- /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
- pub fn search<F: FnOnce(Search) -> Search>(&self, f: F) -> Result<SearchResult> {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id.search(f)
- }
-
- /// Performs a search request to the API for the guild's [`Message`]s in
- /// given channels.
- ///
- /// This will search all of the messages in the guild's provided
- /// [`Channel`]s by Id that you have the [Read Message History] permission
- /// to. Use [`search`] to search all of a guild's [channel][`GuildChannel`]s
- /// at once.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`Channel`]: enum.Channel.html
- /// [`GuildChannel`]: struct.GuildChannel.html
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- /// [`search`]: #method.search
- /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
- pub fn search_channels<F>(&self, channel_ids: &[ChannelId], f: F)
- -> Result<SearchResult> where F: FnOnce(Search) -> Search {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id.search_channels(channel_ids, f)
- }
-
/// Returns the formatted URL of the guild's splash image, if one exists.
pub fn splash_url(&self) -> Option<String> {
self.icon.as_ref().map(|icon|
diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs
index e5d463e..f5ab502 100644
--- a/src/model/guild/partial_guild.rs
+++ b/src/model/guild/partial_guild.rs
@@ -1,6 +1,5 @@
-use ::client::CACHE;
use ::model::*;
-use ::utils::builder::{EditGuild, EditMember, EditRole, Search};
+use ::utils::builder::{EditGuild, EditMember, EditRole};
impl PartialGuild {
/// Ban a [`User`] from the guild. All messages by the
@@ -381,78 +380,6 @@ impl PartialGuild {
self.id.move_member(user_id, channel_id)
}
- /// Performs a search request to the API for the guild's [`Message`]s.
- ///
- /// This will search all of the guild's [`Channel`]s at once, that you have
- /// the [Read Message History] permission to. Use [`search_channels`] to
- /// specify a list of [channel][`GuildChannel`]s to search, where all other
- /// channels will be excluded.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`Channel`]: enum.Channel.html
- /// [`GuildChannel`]: struct.GuildChannel.html
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- /// [`search_channels`]: #method.search_channels
- /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
- pub fn search<F: FnOnce(Search) -> Search>(&self, f: F) -> Result<SearchResult> {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id.search(f)
- }
-
- /// Performs a search request to the API for the guild's [`Message`]s in
- /// given channels.
- ///
- /// This will search all of the messages in the guild's provided
- /// [`Channel`]s by Id that you have the [Read Message History] permission
- /// to. Use [`search`] to search all of a guild's [channel][`GuildChannel`]s
- /// at once.
- ///
- /// Refer to the documentation for the [`Search`] builder for examples and
- /// more information.
- ///
- /// **Note**: Bot users can not search.
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`Channel`]: enum.Channel.html
- /// [`GuildChannel`]: struct.GuildChannel.html
- /// [`Message`]: struct.Message.html
- /// [`Search`]: ../utils/builder/struct.Search.html
- /// [`search`]: #method.search
- /// [Read Message History]: permissions/constant.READ_MESSAGE_HISTORY.html
- pub fn search_channels<F>(&self, channel_ids: &[ChannelId], f: F)
- -> Result<SearchResult> where F: FnOnce(Search) -> Search {
- #[cfg(feature="cache")]
- {
- if CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsBot));
- }
- }
-
- self.id.search_channels(channel_ids, f)
- }
-
/// Returns the formatted URL of the guild's splash image, if one exists.
pub fn splash_url(&self) -> Option<String> {
self.icon.as_ref().map(|icon|
diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs
index 79ffdf8..77d84e1 100644
--- a/src/model/guild/role.rs
+++ b/src/model/guild/role.rs
@@ -1,8 +1,12 @@
use std::cmp::Ordering;
use std::fmt::{Display, Formatter, Result as FmtResult};
+use ::model::*;
+
+#[cfg(feature="cache")]
use ::client::{CACHE, rest};
+#[cfg(feature="cache")]
use ::internal::prelude::*;
-use ::model::*;
+#[cfg(feature="cache")]
use ::utils::builder::EditRole;
impl Role {
diff --git a/src/model/user.rs b/src/model/user.rs
index c69cf39..338011b 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -1,18 +1,14 @@
use serde_json::builder::ObjectBuilder;
use std::{fmt, mem};
-use super::utils::{into_map, into_string, remove};
use super::{
CurrentUser,
- FriendSourceFlags,
GuildContainer,
GuildId,
GuildInfo,
Member,
Message,
- OnlineStatus,
PrivateChannel,
RoleId,
- UserSettings,
User,
UserId,
};
@@ -21,7 +17,6 @@ use ::client::rest::{self, GuildPagination};
use ::internal::prelude::*;
use ::model::misc::Mentionable;
use ::utils::builder::EditProfile;
-use ::utils::decode_array;
#[cfg(feature="cache")]
use std::sync::{Arc, RwLock};
@@ -159,24 +154,6 @@ impl User {
Ok(cdn!("/embed/avatars/{}.png", self.discriminator.parse::<u16>()? % 5u16).to_owned())
}
- /// Deletes a profile note from a user.
- ///
- /// # Examples
- ///
- /// Delete a note for a [`Message`]'s author:
- ///
- /// ```rust,ignore
- /// // assuming you are in a context
- ///
- /// let _ = message.author.delete_note();
- /// ```
- ///
- /// [`Message`]: struct.Message.html
- #[inline]
- pub fn delete_note(&self) -> Result<()> {
- self.id.delete_note()
- }
-
/// Sends a message to a user through a direct message channel. This is a
/// channel that can only be accessed by you and the recipient.
///
@@ -266,35 +243,6 @@ impl User {
self.direct_message(content)
}
- /// Edits the note that the current user has set for another user.
- ///
- /// Use [`delete_note`] to remove a note.
- ///
- /// **Note**: Requires that the current user be a user account.
- ///
- /// # Examples
- ///
- /// Set a note for a message's author:
- ///
- /// ```rust,ignore
- /// // assuming a `message` has been bound
- ///
- /// let _ = message.author.edit_note("test note");
- /// ```
- ///
- /// # Errors
- ///
- /// If the `cache` is enabled, returns a
- /// [`ClientError::InvalidOperationAsBot`] if the current user is a bot
- /// user.
- ///
- /// [`ClientError::InvalidOperationAsBot`]: ../client/enum.ClientError.html#variant.InvalidOperationAsBot
- /// [`delete_note`]: #method.delete_note
- #[inline]
- pub fn edit_note(&self, note: &str) -> Result<()> {
- self.id.edit_note(note)
- }
-
/// Gets a user by its Id over the REST API.
///
/// **Note**: The current user must be a bot user.
@@ -306,14 +254,8 @@ impl User {
/// user.
///
/// [`ClientError::InvalidOperationAsUser`]: ../client/enum.ClientError.html#variant.InvalidOperationAsUser
+ #[inline]
pub fn get<U: Into<UserId>>(user_id: U) -> Result<User> {
- #[cfg(feature="cache")]
- {
- if !CACHE.read().unwrap().user.bot {
- return Err(Error::Client(ClientError::InvalidOperationAsUser));
- }
- }
-
user_id.into().get()
}
@@ -389,29 +331,6 @@ impl UserId {
rest::create_private_channel(&map)
}
- /// Deletes a profile note from a user.
- pub fn delete_note(&self) -> Result<()> {
- let map = ObjectBuilder::new().insert("note", "").build();
-
- rest::edit_note(self.0, &map)
- }
-
- /// Edits the note that the current user has set for another user.
- ///
- /// Use [`delete_note`] to remove a note.
- ///
- /// Refer to the documentation for [`User::edit_note`] for more information.
- ///
- /// **Note**: Requires that the current user be a user account.
- ///
- /// [`delete_note`]: #method.delete_note
- /// [`User::edit_note`]: struct.User.html#method.edit_note
- pub fn edit_note(&self, note: &str) -> Result<()> {
- let map = ObjectBuilder::new().insert("note", note).build();
-
- rest::edit_note(self.0, &map)
- }
-
/// Search the cache for the user with the Id.
#[cfg(feature="cache")]
pub fn find(&self) -> Option<Arc<RwLock<User>>> {
@@ -453,29 +372,3 @@ impl fmt::Display for UserId {
fmt::Display::fmt(&self.0, f)
}
}
-
-impl UserSettings {
- #[doc(hidden)]
- pub fn decode(value: Value) -> Result<Option<UserSettings>> {
- let mut map = into_map(value)?;
-
- if map.is_empty() {
- return Ok(None);
- }
-
- Ok(UserSettings {
- convert_emoticons: req!(remove(&mut map, "convert_emoticons")?.as_bool()),
- enable_tts_command: req!(remove(&mut map, "enable_tts_command")?.as_bool()),
- friend_source_flags: remove(&mut map, "friend_source_flags").and_then(FriendSourceFlags::decode)?,
- inline_attachment_media: req!(remove(&mut map, "inline_attachment_media")?.as_bool()),
- inline_embed_media: req!(remove(&mut map, "inline_embed_media")?.as_bool()),
- locale: remove(&mut map, "locale").and_then(into_string)?,
- message_display_compact: req!(remove(&mut map, "message_display_compact")?.as_bool()),
- render_embeds: req!(remove(&mut map, "render_embeds")?.as_bool()),
- restricted_guilds: remove(&mut map, "restricted_guilds").and_then(|v| decode_array(v, GuildId::decode))?,
- show_current_game: req!(remove(&mut map, "show_current_game")?.as_bool()),
- theme: remove(&mut map, "theme").and_then(into_string)?,
- status: remove(&mut map, "status").and_then(OnlineStatus::decode_str)?,
- }).map(Some)
- }
-}
diff --git a/src/model/utils.rs b/src/model/utils.rs
index 17f91f1..cbae244 100644
--- a/src/model/utils.rs
+++ b/src/model/utils.rs
@@ -30,36 +30,6 @@ pub fn decode_emojis(value: Value) -> Result<HashMap<EmojiId, Emoji>> {
Ok(emojis)
}
-pub fn decode_experiments(value: Value) -> Result<Vec<Vec<u64>>> {
- let array = match value {
- Value::Array(v) => v,
- value => return Err(Error::Decode("Expected experiment array", value)),
- };
-
- let mut experiments: Vec<Vec<u64>> = vec![];
-
- for arr in array {
- let arr = match arr {
- Value::Array(v) => v,
- value => return Err(Error::Decode("Expected experiment's array", value)),
- };
-
- let mut items: Vec<u64> = vec![];
-
- for item in arr {
- items.push(match item {
- Value::I64(v) => v as u64,
- Value::U64(v) => v,
- value => return Err(Error::Decode("Expected experiment u64", value)),
- });
- }
-
- experiments.push(items);
- }
-
- Ok(experiments)
-}
-
pub fn decode_id(value: Value) -> Result<u64> {
match value {
Value::U64(num) => Ok(num),
@@ -102,25 +72,6 @@ pub fn decode_guild_members(guild_id: GuildId, value: Value) -> Result<HashMap<U
Ok(members)
}
-// Clippy's lint is incorrect here and will result in invalid code.
-//
-// Bit more detaul: `result_unwrap_or_default` is not yet stable as of rustc
-// 1.14.
-#[allow(or_fun_call)]
-pub fn decode_notes(value: Value) -> Result<HashMap<UserId, String>> {
- let mut notes = HashMap::new();
-
- for (key, value) in into_map(value).unwrap_or(BTreeMap::default()) {
- let id = UserId(key.parse::<u64>()
- .map_err(|_| Error::Decode("Invalid user id in notes",
- Value::String(key)))?);
-
- notes.insert(id, into_string(value)?);
- }
-
- Ok(notes)
-}
-
pub fn decode_presences(value: Value) -> Result<HashMap<UserId, Presence>> {
let mut presences = HashMap::new();
@@ -148,28 +99,6 @@ pub fn decode_private_channels(value: Value)
Ok(private_channels)
}
-pub fn decode_read_states(value: Value)
- -> Result<HashMap<ChannelId, ReadState>> {
- let mut read_states = HashMap::new();
-
- for read_state in decode_array(value, ReadState::decode)? {
- read_states.insert(read_state.id, read_state);
- }
-
- Ok(read_states)
-}
-
-pub fn decode_relationships(value: Value)
- -> Result<HashMap<UserId, Relationship>> {
- let mut relationships = HashMap::new();
-
- for relationship in decode_array(value, Relationship::decode)? {
- relationships.insert(relationship.id, relationship);
- }
-
- Ok(relationships)
-}
-
pub fn decode_roles(value: Value) -> Result<HashMap<RoleId, Role>> {
let mut roles = HashMap::new();
@@ -180,35 +109,6 @@ pub fn decode_roles(value: Value) -> Result<HashMap<RoleId, Role>> {
Ok(roles)
}
-pub fn decode_search_results(value: Value) -> Result<Vec<Vec<Message>>> {
- let array = match value {
- Value::Array(v) => v,
- value => return Err(Error::Decode("Expected message set array", value)),
- };
-
- let mut sets: Vec<Vec<Message>> = vec![];
-
- for arr in array {
- let arr = match arr {
- Value::Array(v) => v,
- value => return Err(Error::Decode("Expected message set array", value)),
- };
-
- let mut messages: Vec<Message> = vec![];
-
- for item in arr {
- messages.push(match item {
- Value::Object(v) => try!(Message::decode(Value::Object(v))),
- value => return Err(Error::Decode("Expected search message", value)),
- });
- }
-
- sets.push(messages);
- }
-
- Ok(sets)
-}
-
pub fn decode_shards(value: Value) -> Result<[u64; 2]> {
let array = into_array(value)?;