aboutsummaryrefslogtreecommitdiff
path: root/src/model/channel
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/channel
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/channel')
-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
8 files changed, 23 insertions, 274 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.