diff options
| author | Zeyla Hellyer <[email protected]> | 2017-04-05 08:14:43 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-04-05 08:55:01 -0700 |
| commit | d9118c081742d6654dc0a4f60228a7a212ca436e (patch) | |
| tree | 003f49f54769314c1111e942d77f57513406fb5e /src | |
| parent | Add a sample bot structure example (diff) | |
| download | serenity-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')
35 files changed, 150 insertions, 1838 deletions
diff --git a/src/client/context.rs b/src/client/context.rs index f46e351..d208140 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -2,7 +2,6 @@ use serde_json::builder::ObjectBuilder; use std::sync::{Arc, Mutex}; use super::gateway::Shard; use super::rest; -use super::login_type::LoginType; use typemap::ShareMap; use ::utils::builder::EditProfile; use ::internal::prelude::*; @@ -45,7 +44,6 @@ pub struct Context { pub shard: Arc<Mutex<Shard>>, /// The queue of messages that are sent after context goes out of scope. pub queue: String, - login_type: LoginType, } impl Context { @@ -59,13 +57,11 @@ impl Context { #[doc(hidden)] pub fn new(channel_id: Option<ChannelId>, shard: Arc<Mutex<Shard>>, - data: Arc<Mutex<ShareMap>>, - login_type: LoginType) -> Context { + data: Arc<Mutex<ShareMap>>) -> Context { Context { channel_id: channel_id, data: data, shard: shard, - login_type: login_type, queue: String::new(), } } diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 33267ff..49dbdb0 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -1,7 +1,6 @@ use std::sync::{Arc, Mutex, RwLock}; use std::thread; use super::event_store::EventStore; -use super::login_type::LoginType; use super::Context; use super::gateway::Shard; use typemap::ShareMap; @@ -61,9 +60,8 @@ macro_rules! update { fn context(channel_id: Option<ChannelId>, conn: &Arc<Mutex<Shard>>, - data: &Arc<Mutex<ShareMap>>, - login_type: LoginType) -> Context { - Context::new(channel_id, conn.clone(), data.clone(), login_type) + data: &Arc<Mutex<ShareMap>>) -> Context { + Context::new(channel_id, conn.clone(), data.clone()) } #[cfg(feature="framework")] @@ -71,14 +69,12 @@ pub fn dispatch(event: Event, conn: &Arc<Mutex<Shard>>, framework: &Arc<Mutex<Framework>>, data: &Arc<Mutex<ShareMap>>, - login_type: LoginType, event_store: &Arc<RwLock<EventStore>>) { match event { Event::MessageCreate(event) => { let context = context(Some(event.message.channel_id), conn, - data, - login_type); + data); let mut framework = framework.lock().unwrap(); if framework.initialized { @@ -91,7 +87,7 @@ pub fn dispatch(event: Event, dispatch_message(context, event.message, event_store); } }, - other => handle_event(other, conn, data, login_type, event_store), + other => handle_event(other, conn, data, event_store), } } @@ -99,19 +95,15 @@ pub fn dispatch(event: Event, pub fn dispatch(event: Event, conn: &Arc<Mutex<Shard>>, data: &Arc<Mutex<ShareMap>>, - login_type: LoginType, event_store: &Arc<RwLock<EventStore>>) { match event { Event::MessageCreate(event) => { - let context = context(Some(event.message.channel_id), - conn, - data, - login_type); + let context = context(Some(event.message.channel_id), conn, data); dispatch_message(context, event.message, event_store); }, - other => handle_event(other, conn, data, login_type, event_store), + other => handle_event(other, conn, data, event_store), } } @@ -127,14 +119,13 @@ fn dispatch_message(context: Context, fn handle_event(event: Event, conn: &Arc<Mutex<Shard>>, data: &Arc<Mutex<ShareMap>>, - login_type: LoginType, event_store: &Arc<RwLock<EventStore>>) { match event { Event::CallCreate(event) => { if let Some(handler) = handler!(on_call_create, event_store) { update!(update_with_call_create, event); - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.call)); } else { @@ -143,7 +134,7 @@ fn handle_event(event: Event, }, Event::CallDelete(event) => { if let Some(handler) = handler!(on_call_delete, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let call = update!(update_with_call_delete, event); @@ -158,7 +149,7 @@ fn handle_event(event: Event, }, Event::CallUpdate(event) => { if let Some(handler) = handler!(on_call_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let before = update!(update_with_call_update, event, true); @@ -183,10 +174,7 @@ fn handle_event(event: Event, Event::ChannelCreate(event) => { if let Some(handler) = handler!(on_channel_create, event_store) { update!(update_with_channel_create, event); - let context = context(Some(event.channel.id()), - conn, - data, - login_type); + let context = context(Some(event.channel.id()), conn, data); thread::spawn(move || (handler)(context, event.channel)); } else { @@ -196,7 +184,7 @@ fn handle_event(event: Event, Event::ChannelDelete(event) => { if let Some(handler) = handler!(on_channel_delete, event_store) { update!(update_with_channel_delete, event); - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.channel)); } else { @@ -205,20 +193,14 @@ fn handle_event(event: Event, }, Event::ChannelPinsAck(event) => { if let Some(handler) = handler!(on_channel_pins_ack, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event)); } }, Event::ChannelPinsUpdate(event) => { if let Some(handler) = handler!(on_channel_pins_update, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event)); } @@ -227,10 +209,7 @@ fn handle_event(event: Event, update!(update_with_channel_recipient_add, @event); if let Some(handler) = handler!(on_channel_recipient_addition, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event.channel_id, event.user)); } @@ -239,20 +218,14 @@ fn handle_event(event: Event, update!(update_with_channel_recipient_remove, event); if let Some(handler) = handler!(on_channel_recipient_removal, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event.channel_id, event.user)); } }, Event::ChannelUpdate(event) => { if let Some(handler) = handler!(on_channel_update, event_store) { - let context = context(Some(event.channel.id()), - conn, - data, - login_type); + let context = context(Some(event.channel.id()), conn, data); feature_cache! {{ let before = CACHE.read() @@ -268,30 +241,16 @@ fn handle_event(event: Event, update!(update_with_channel_update, event); } }, - Event::FriendSuggestionCreate(event) => { - if let Some(handler) = handler!(on_friend_suggestion_create, event_store) { - let context = context(None, conn, data, login_type); - - thread::spawn(move || (handler)(context, event.suggested_user, event.reasons)); - } - }, - Event::FriendSuggestionDelete(event) => { - if let Some(handler) = handler!(on_friend_suggestion_delete, event_store) { - let context = context(None, conn, data, login_type); - - thread::spawn(move || (handler)(context, event.suggested_user_id)); - } - }, Event::GuildBanAdd(event) => { if let Some(handler) = handler!(on_guild_ban_addition, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id, event.user)); } }, Event::GuildBanRemove(event) => { if let Some(handler) = handler!(on_guild_ban_removal, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id, event.user)); } @@ -300,14 +259,14 @@ fn handle_event(event: Event, update!(update_with_guild_create, event); if let Some(handler) = handler!(on_guild_create, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild)); } }, Event::GuildDelete(event) => { if let Some(handler) = handler!(on_guild_delete, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let full = update!(update_with_guild_delete, event); @@ -327,14 +286,14 @@ fn handle_event(event: Event, update!(update_with_guild_emojis_update, event); if let Some(handler) = handler!(on_guild_emojis_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id, event.emojis)); } }, Event::GuildIntegrationsUpdate(event) => { if let Some(handler) = handler!(on_guild_integrations_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id)); } @@ -343,14 +302,14 @@ fn handle_event(event: Event, update!(update_with_guild_member_add, @event); if let Some(handler) = handler!(on_guild_member_addition, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id, event.member)); } }, Event::GuildMemberRemove(event) => { if let Some(handler) = handler!(on_guild_member_removal, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let member = update!(update_with_guild_member_remove, event); @@ -368,7 +327,7 @@ fn handle_event(event: Event, }, Event::GuildMemberUpdate(event) => { if let Some(handler) = handler!(on_guild_member_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let before = update!(update_with_guild_member_update, event); @@ -394,7 +353,7 @@ fn handle_event(event: Event, update!(update_with_guild_members_chunk, event); if let Some(handler) = handler!(on_guild_members_chunk, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id, event.members)); } @@ -403,14 +362,14 @@ fn handle_event(event: Event, update!(update_with_guild_role_create, event); if let Some(handler) = handler!(on_guild_role_create, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id, event.role)); } }, Event::GuildRoleDelete(event) => { if let Some(handler) = handler!(on_guild_role_delete, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let role = update!(update_with_guild_role_delete, event); @@ -428,7 +387,7 @@ fn handle_event(event: Event, }, Event::GuildRoleUpdate(event) => { if let Some(handler) = handler!(on_guild_role_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let before = update!(update_with_guild_role_update, event); @@ -446,7 +405,7 @@ fn handle_event(event: Event, }, Event::GuildSync(event) => { if let Some(handler) = handler!(on_guild_sync, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event)); } @@ -455,14 +414,14 @@ fn handle_event(event: Event, update!(update_with_guild_unavailable, event); if let Some(handler) = handler!(on_guild_unavailable, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id)); } }, Event::GuildUpdate(event) => { if let Some(handler) = handler!(on_guild_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let before = CACHE.read() @@ -479,45 +438,26 @@ fn handle_event(event: Event, } else { update!(update_with_guild_update, event); } - } - Event::MessageAck(event) => { - if let Some(handler) = handler!(on_message_ack, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); - - thread::spawn(move || (handler)(context, event.channel_id, event.message_id)); - } }, // Already handled by the framework check macro Event::MessageCreate(_) => {}, Event::MessageDeleteBulk(event) => { if let Some(handler) = handler!(on_message_delete_bulk, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event.channel_id, event.ids)); } }, Event::MessageDelete(event) => { if let Some(handler) = handler!(on_message_delete, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event.channel_id, event.message_id)); } }, Event::MessageUpdate(event) => { if let Some(handler) = handler!(on_message_update, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event)); } @@ -526,7 +466,7 @@ fn handle_event(event: Event, update!(update_with_presences_replace, event); if let Some(handler) = handler!(on_presence_replace, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.presences)); } @@ -535,37 +475,28 @@ fn handle_event(event: Event, update!(update_with_presence_update, @event); if let Some(handler) = handler!(on_presence_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event)); } }, Event::ReactionAdd(event) => { if let Some(handler) = handler!(on_reaction_add, event_store) { - let context = context(Some(event.reaction.channel_id), - conn, - data, - login_type); + let context = context(Some(event.reaction.channel_id), conn, data); thread::spawn(move || (handler)(context, event.reaction)); } }, Event::ReactionRemove(event) => { if let Some(handler) = handler!(on_reaction_remove, event_store) { - let context = context(Some(event.reaction.channel_id), - conn, - data, - login_type); + let context = context(Some(event.reaction.channel_id), conn, data); thread::spawn(move || (handler)(context, event.reaction)); } }, Event::ReactionRemoveAll(event) => { if let Some(handler) = handler!(on_reaction_remove_all, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event.channel_id, event.message_id)); } @@ -574,117 +505,37 @@ fn handle_event(event: Event, if let Some(handler) = handler!(on_ready, event_store) { update!(update_with_ready, event); - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.ready)); } else { update!(update_with_ready, event); } }, - Event::RelationshipAdd(event) => { - update!(update_with_relationship_add, event); - - if let Some(handler) = handler!(on_relationship_addition, event_store) { - let context = context(None, conn, data, login_type); - - thread::spawn(move || (handler)(context, event.relationship)); - } - }, - Event::RelationshipRemove(event) => { - update!(update_with_relationship_remove, event); - - if let Some(handler) = handler!(on_relationship_removal, event_store) { - let context = context(None, conn, data, login_type); - - thread::spawn(move || (handler)(context, event.user_id, event.kind)); - } - }, Event::Resumed(event) => { if let Some(handler) = handler!(on_resume, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event)); } }, Event::TypingStart(event) => { if let Some(handler) = handler!(on_typing_start, event_store) { - let context = context(Some(event.channel_id), - conn, - data, - login_type); + let context = context(Some(event.channel_id), conn, data); thread::spawn(move || (handler)(context, event)); } }, Event::Unknown(event) => { if let Some(handler) = handler!(on_unknown, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.kind, event.value)); } }, - Event::UserGuildSettingsUpdate(event) => { - if let Some(handler) = handler!(on_user_guild_settings_update, event_store) { - let context = context(None, conn, data, login_type); - - feature_cache! {{ - let before = update!(update_with_user_guild_settings_update, event); - - thread::spawn(move || (handler)(context, before, event.settings)); - } else { - thread::spawn(move || (handler)(context, event.settings)); - }} - } else { - #[cfg(feature="cache")] - { - let _ = update!(update_with_user_guild_settings_update, event); - } - } - }, - Event::UserNoteUpdate(event) => { - if let Some(handler) = handler!(on_note_update, event_store) { - let context = context(None, conn, data, login_type); - - feature_cache! {{ - let before = update!(update_with_user_note_update, event); - - thread::spawn(move || (handler)(context, event.user_id, before, event.note)); - } else { - thread::spawn(move || (handler)(context, event.user_id, event.note)); - }} - } else { - #[cfg(feature="cache")] - { - let _ = update!(update_with_user_note_update, event); - } - } - }, - Event::UserSettingsUpdate(event) => { - if let Some(handler) = handler!(on_user_settings_update, event_store) { - let context = context(None, conn, data, login_type); - - feature_cache! {{ - let before = update!(update_with_user_settings_update, event, true); - let after = CACHE.read().unwrap().settings.clone(); - - // Unwrap in the spawned thread so that if they don't - // actually exist, then the current thread won't panic. - // - // Yes, this is probably bad. - thread::spawn(move || (handler)(context, before.unwrap(), after.unwrap())); - } else { - thread::spawn(move || (handler)(context, event)); - }} - } else { - #[cfg(feature="cache")] - { - update!(update_with_user_settings_update, event, false); - } - } - }, Event::UserUpdate(event) => { if let Some(handler) = handler!(on_user_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); feature_cache! {{ let before = update!(update_with_user_update, event); @@ -702,7 +553,7 @@ fn handle_event(event: Event, }, Event::VoiceServerUpdate(event) => { if let Some(handler) = handler!(on_voice_server_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event)); } @@ -711,14 +562,14 @@ fn handle_event(event: Event, update!(update_with_voice_state_update, event); if let Some(handler) = handler!(on_voice_state_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id, event.voice_state)); } }, Event::WebhookUpdate(event) => { if let Some(handler) = handler!(on_webhook_update, event_store) { - let context = context(None, conn, data, login_type); + let context = context(None, conn, data); thread::spawn(move || (handler)(context, event.guild_id, event.channel_id)); } diff --git a/src/client/error.rs b/src/client/error.rs index 30d3c27..6a18b7a 100644 --- a/src/client/error.rs +++ b/src/client/error.rs @@ -19,7 +19,7 @@ use ::model::{ChannelType, Permissions}; /// use std::env; /// /// let token = env::var("DISCORD_BOT_TOKEN").unwrap(); -/// let mut client = Client::login_bot(&token); +/// let mut client = Client::login(&token); /// /// client.on_member_unban(|context, guild_id, user| { /// let discriminator = user.discriminator.parse::<u16>().unwrap(); @@ -74,12 +74,6 @@ pub enum Error { GuildNotFound, /// An indicator that an unknown opcode was received from the gateway. InvalidOpCode, - /// When attempting to perform an action which is only available to user - /// accounts. - InvalidOperationAsBot, - /// When attempting to perform an action which is only available to bot - /// accounts. - InvalidOperationAsUser, /// Indicates that you do not have the required permissions to perform an /// operation. /// diff --git a/src/client/event_store.rs b/src/client/event_store.rs index f63c03a..cc74d63 100644 --- a/src/client/event_store.rs +++ b/src/client/event_store.rs @@ -18,11 +18,7 @@ use ::model::*; use std::sync::RwLock; #[cfg(not(feature="cache"))] -use ::model::event::{ - CallUpdateEvent, - GuildMemberUpdateEvent, - UserSettingsUpdateEvent, -}; +use ::model::event::{CallUpdateEvent, GuildMemberUpdateEvent}; // This should use type macros when stable receives the type macro // stabilization patch. @@ -64,8 +60,6 @@ pub struct EventStore { pub on_channel_update: Option<Arc<Fn(Context, Option<Channel>, Channel) + Send + Sync + 'static>>, #[cfg(not(feature="cache"))] pub on_channel_update: Option<Arc<Fn(Context, Channel) + Send + Sync + 'static>>, - pub on_friend_suggestion_create: Option<Arc<Fn(Context, User, Vec<SuggestionReason>) + Send + Sync + 'static>>, - pub on_friend_suggestion_delete: Option<Arc<Fn(Context, UserId) + Send + Sync + 'static>>, pub on_guild_ban_addition: Option<Arc<Fn(Context, GuildId, User) + Send + Sync + 'static>>, pub on_guild_ban_removal: Option<Arc<Fn(Context, GuildId, User) + Send + Sync + 'static>>, pub on_guild_create: Option<Arc<Fn(Context, Guild) + Send + Sync + 'static>>, @@ -108,30 +102,16 @@ pub struct EventStore { pub on_reaction_remove: Option<Arc<Fn(Context, Reaction) + Send + Sync + 'static>>, pub on_reaction_remove_all: Option<Arc<Fn(Context, ChannelId, MessageId) + Send + Sync + 'static>>, pub on_message_update: Option<Arc<Fn(Context, MessageUpdateEvent) + Send + Sync + 'static>>, - #[cfg(feature="cache")] - pub on_note_update: Option<Arc<Fn(Context, UserId, Option<String>, String) + Send + Sync + 'static>>, - #[cfg(not(feature="cache"))] - pub on_note_update: Option<Arc<Fn(Context, UserId, String) + Send + Sync + 'static>>, pub on_presence_replace: Option<Arc<Fn(Context, Vec<Presence>) + Send + Sync + 'static>>, pub on_presence_update: Option<Arc<Fn(Context, PresenceUpdateEvent) + Send + Sync + 'static>>, pub on_ready: Option<Arc<Fn(Context, Ready) + Send + Sync + 'static>>, - pub on_relationship_addition: Option<Arc<Fn(Context, Relationship) + Send + Sync + 'static>>, - pub on_relationship_removal: Option<Arc<Fn(Context, UserId, RelationshipType) + Send + Sync + 'static>>, pub on_resume: Option<Arc<Fn(Context, ResumedEvent) + Send + Sync + 'static>>, pub on_typing_start: Option<Arc<Fn(Context, TypingStartEvent) + Send + Sync + 'static>>, pub on_unknown: Option<Arc<Fn(Context, String, BTreeMap<String, Value>) + Send + Sync + 'static>>, #[cfg(feature="cache")] - pub on_user_guild_settings_update: Option<Arc<Fn(Context, Option<UserGuildSettings>, UserGuildSettings) + Send + Sync + 'static>>, - #[cfg(not(feature="cache"))] - pub on_user_guild_settings_update: Option<Arc<Fn(Context, UserGuildSettings) + Send + Sync + 'static>>, - #[cfg(feature="cache")] pub on_user_update: Option<Arc<Fn(Context, CurrentUser, CurrentUser) + Send + Sync + 'static>>, #[cfg(not(feature="cache"))] pub on_user_update: Option<Arc<Fn(Context, CurrentUser) + Send + Sync + 'static>>, - #[cfg(feature="cache")] - pub on_user_settings_update: Option<Arc<Fn(Context, UserSettings, UserSettings) + Send + Sync + 'static>>, - #[cfg(not(feature="cache"))] - pub on_user_settings_update: Option<Arc<Fn(Context, UserSettingsUpdateEvent) + Send + Sync + 'static>>, pub on_voice_server_update: Option<Arc<Fn(Context, VoiceServerUpdateEvent) + Send + Sync + 'static>>, pub on_voice_state_update: Option<Arc<Fn(Context, Option<GuildId>, VoiceState) + Send + Sync + 'static>>, pub on_webhook_update: Option<Arc<Fn(Context, GuildId, ChannelId) + Send + Sync + 'static>>, diff --git a/src/client/gateway/shard.rs b/src/client/gateway/shard.rs index e4c4720..f42c52a 100644 --- a/src/client/gateway/shard.rs +++ b/src/client/gateway/shard.rs @@ -6,7 +6,6 @@ use std::sync::{Arc, Mutex}; use std::thread::{self, Builder as ThreadBuilder}; use std::time::{Duration as StdDuration, Instant}; use std::mem; -use super::super::login_type::LoginType; use super::super::rest; use super::{GatewayError, GatewayStatus, prep}; use time; @@ -73,7 +72,6 @@ pub struct Shard { heartbeat_instants: (Arc<Mutex<Instant>>, Option<Instant>), keepalive_channel: MpscSender<GatewayStatus>, seq: u64, - login_type: LoginType, session_id: Option<String>, shard_info: Option<[u64; 2]>, token: String, @@ -96,13 +94,13 @@ impl Shard { /// /// ```rust,ignore /// use serenity::client::gateway::Shard; - /// use serenity::client::{LoginType, rest}; + /// use serenity::client::rest; /// use std::env; /// /// let token = env::var("DISCORD_BOT_TOKEN").expect("Token in environment"); /// // retrieve the gateway response, which contains the URL to connect to /// let gateway = rest::get_gateway().expect("Valid gateway response").url; - /// let shard = Shard::new(&gateway, &token, None, LoginType::Bot) + /// let shard = Shard::new(&gateway, &token, None) /// .expect("Working shard"); /// /// // at this point, you can create a `loop`, and receive events and match @@ -110,8 +108,7 @@ impl Shard { /// ``` pub fn new(base_url: &str, token: &str, - shard_info: Option<[u64; 2]>, - login_type: LoginType) + shard_info: Option<[u64; 2]>) -> Result<(Shard, ReadyEvent, Receiver<WebSocketStream>)> { let url = prep::build_gateway_url(base_url)?; @@ -162,7 +159,6 @@ impl Shard { heartbeat_instants: (heartbeat_sent, None), keepalive_channel: tx.clone(), seq: sequence, - login_type: login_type, token: token.to_owned(), session_id: Some(ready.ready.session_id.clone()), shard_info: shard_info, @@ -175,7 +171,6 @@ impl Shard { heartbeat_instants: (heartbeat_sent, None), keepalive_channel: tx.clone(), seq: sequence, - login_type: login_type, token: token.to_owned(), session_id: Some(ready.ready.session_id.clone()), shard_info: shard_info, @@ -528,16 +523,6 @@ impl Shard { let _ = self.keepalive_channel.send(GatewayStatus::SendMessage(msg)); } - /// Syncs the user's guilds. - pub fn sync_guilds(&self, guild_ids: &[GuildId]) { - let msg = ObjectBuilder::new() - .insert("op", OpCode::SyncGuild.num()) - .insert_array("d", |a| guild_ids.iter().fold(a, |a, s| a.push(s.0))) - .build(); - - let _ = self.keepalive_channel.send(GatewayStatus::SendMessage(msg)); - } - #[allow(unused_variables)] fn handle_dispatch(&mut self, event: &Event) { #[cfg(feature="voice")] @@ -570,8 +555,7 @@ impl Shard { let shard = Shard::new(&gateway_url, &self.token, - self.shard_info, - self.login_type); + self.shard_info); if let Ok((shard, ready, receiver_new)) = shard { let _ = Shard::shutdown(&mut receiver); diff --git a/src/client/login_type.rs b/src/client/login_type.rs deleted file mode 100644 index 4eae5e2..0000000 --- a/src/client/login_type.rs +++ /dev/null @@ -1,24 +0,0 @@ -/// The type of login to perform. -/// -/// Use [`Bot`] if you are using a bot which responds to others, created through -/// the [applications page]. See the [`README`] for more information on using -/// bots. -/// -/// Use [`User`] if you are creating a selfbot which responds only to you. -/// -/// [`Bot`]: #variant.Bot -/// [`README`]: https://github.com/zeyla/serenity/blob/master/README.md#Bots -/// [`User`]: #variant.User -/// [applications page]: https://discordapp.com/developers/applications/me -#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Ord, PartialOrd)] -pub enum LoginType { - /// An indicator to login as a bot. This will automatically prefix your - /// token with `"Bot "`, which is a requirement by Discord. - Bot, - /// An indicator to login under your own user account token. Only use this - /// if you are creating a "selfbot", which triggers on events from yourself. - /// - /// **Note**: _Do not_ use this for a "userbot" which responds to others, or - /// you _can_ be banned. - User, -} diff --git a/src/client/mod.rs b/src/client/mod.rs index e9ba20b..9286379 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -27,11 +27,9 @@ mod context; mod dispatch; mod error; mod event_store; -mod login_type; pub use self::context::Context; pub use self::error::Error as ClientError; -pub use self::login_type::LoginType; use self::dispatch::dispatch; use self::event_store::EventStore; @@ -68,11 +66,7 @@ use ::ext::framework::Framework; use ::ext::cache::Cache; #[cfg(not(feature="cache"))] -use ::model::event::{ - CallUpdateEvent, - GuildMemberUpdateEvent, - UserSettingsUpdateEvent, -}; +use ::model::event::{CallUpdateEvent, GuildMemberUpdateEvent}; #[cfg(feature="cache")] lazy_static! { @@ -135,7 +129,7 @@ lazy_static! { /// ```rust,ignore /// use serenity::Client; /// -/// let mut client = Client::login_bot("my token here"); +/// let mut client = Client::login("my token here"); /// /// client.on_message(|context, message| { /// if message.content == "!ping" { @@ -163,10 +157,10 @@ pub struct Client { /// In the meaning of a context, this data can be accessed through /// [`Context::data`]. /// - /// Refer to [example 06] for an example on using the `data` field. + /// Refer to [example 05] for an example on using the `data` field. /// /// [`Context::data`]: struct.Context.html#method.data - /// [example 06]: https://github.com/zeyla/serenity/tree/master/examples/06_command_framework + /// [example 05]: https://github.com/zeyla/serenity/tree/master/examples/05_command_framework pub data: Arc<Mutex<ShareMap>>, /// A vector of all active shards that have received their [`Event::Ready`] /// payload, and have dispatched to [`on_ready`] if an event handler was @@ -177,34 +171,32 @@ pub struct Client { event_store: Arc<RwLock<EventStore>>, #[cfg(feature="framework")] framework: Arc<Mutex<Framework>>, - login_type: LoginType, token: String, } #[allow(type_complexity)] impl Client { + /// Alias of [`login`]. + /// + /// [`login`]: #method.login + #[deprecated(since="0.1.5", note="Use `login` instead")] + #[inline] + pub fn login_bot(token: &str) -> Self { + Self::login(token) + } + /// Creates a Client for a bot user. /// /// Discord has a requirement of prefixing bot tokens with `"Bot "`, which /// this function will automatically do for you if not already included. - pub fn login_bot(bot_token: &str) -> Client { + pub fn login(bot_token: &str) -> Self { let token = if bot_token.starts_with("Bot ") { bot_token.to_owned() } else { format!("Bot {}", bot_token) }; - login(token, LoginType::Bot) - } - - /// Creates a Client for a user. - /// - /// **Note**: Read the notes for [`LoginType::User`] prior to using this, as - /// there are restrictions on usage. - /// - /// [`LoginType::User`]: enum.LoginType.html#variant.User - pub fn login_user(user_token: &str) -> Client { - login(user_token.to_owned(), LoginType::User) + login(token) } /// Sets a framework to be used with the client. All message events will be @@ -322,7 +314,7 @@ impl Client { /// use std::env; /// /// let token = env::var("DISCORD_BOT_TOKEN").unwrap(); - /// let mut client = Client::login_bot(&token); + /// let mut client = Client::login(&token); /// /// let _ = client.start_shard_range([4, 7], 10); /// ``` @@ -384,26 +376,6 @@ impl Client { .on_channel_pins_update = Some(Arc::new(handler)); } - /// Attaches a handler for when a [`FriendSuggestionCreate`] is received. - /// - /// [`FriendSuggestionCreate`]: ../model/event/enum.Event.html#variant.FriendSuggestionCreate - pub fn on_friend_suggestion_create<F>(&mut self, handler: F) - where F: Fn(Context, User, Vec<SuggestionReason>) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_friend_suggestion_create = Some(Arc::new(handler)); - } - - /// Attaches a handler for when a [`FriendSuggestionDelete`] is received. - /// - /// [`FriendSuggestionDelete`]: ../model/event/enum.Event.html#variant.FriendSuggestionDelete - pub fn on_friend_suggestion_delete<F>(&mut self, handler: F) - where F: Fn(Context, UserId) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_friend_suggestion_delete = Some(Arc::new(handler)); - } - /// Attaches a handler for when a [`GuildCreate`] is received. /// /// [`GuildCreate`]: ../model/event/enum.Event.html#variant.GuildCreate @@ -515,7 +487,7 @@ impl Client { /// ```rust,ignore /// use serenity::Client; /// - /// let mut client = Client::login_bot("bot token here"); + /// let mut client = Client::login("bot token here"); /// /// client.on_message(|_context, message| { /// println!("{}", message.content); @@ -640,7 +612,7 @@ impl Client { /// use std::env; /// /// let token = env::var("DISCORD_BOT_TOKEN").unwrap(); - /// let mut client = Client::login_bot(&token); + /// let mut client = Client::login(&token); /// /// client.on_ready(|_context, ready| { /// println!("{} is connected", ready.user.name); @@ -676,26 +648,6 @@ impl Client { .on_channel_recipient_removal = Some(Arc::new(handler)); } - /// Attaches a handler for when a [`RelationshipAdd`] is received. - /// - /// [`RelationshipAdd`]: ../model/event/enum.Event.html#variant.RelationshipAdd - pub fn on_relationship_add<F>(&mut self, handler: F) - where F: Fn(Context, Relationship) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_relationship_addition = Some(Arc::new(handler)); - } - - /// Attaches a handler for when a [`RelationshipRemove`] is received. - /// - /// [`RelationshipRemove`]: ../model/event/enum.Event.html#variant.RelationshipRemove - pub fn on_relationship_remove<F>(&mut self, handler: F) - where F: Fn(Context, UserId, RelationshipType) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_relationship_removal = Some(Arc::new(handler)); - } - /// Attaches a handler for when a [`Resumed`] is received. /// /// [`Resumed`]: ../model/event/enum.Event.html#variant.Resumed @@ -785,7 +737,6 @@ impl Client { let boot = boot_shard(&BootInfo { gateway_url: gateway_url.clone(), - login_type: self.login_type, shard_info: shard_info, token: self.token.clone(), }); @@ -806,13 +757,11 @@ impl Client { &shard, &self.framework, &self.data, - self.login_type, &self.event_store); } else { dispatch(Event::Ready(ready), &shard, &self.data, - self.login_type, &self.event_store); }} @@ -822,7 +771,6 @@ impl Client { event_store: self.event_store.clone(), framework: self.framework.clone(), gateway_url: gateway_url.clone(), - login_type: self.login_type, receiver: receiver, shard: shard, shard_info: shard_info, @@ -833,7 +781,6 @@ impl Client { data: self.data.clone(), event_store: self.event_store.clone(), gateway_url: gateway_url.clone(), - login_type: self.login_type, receiver: receiver, shard: shard, shard_info: shard_info, @@ -964,16 +911,6 @@ impl Client { .on_guild_role_update = Some(Arc::new(handler)); } - /// Attaches a handler for when a [`UserGuildSettingsUpdate`] is received. - /// - /// [`UserGuildSettingsUpdate`]: ../model/event/enum.Event.html#variant.UserGuildSettingsUpdate - pub fn on_user_guild_settings_update<F>(&mut self, handler: F) - where F: Fn(Context, Option<UserGuildSettings>, UserGuildSettings) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_user_guild_settings_update = Some(Arc::new(handler)); - } - /// Attaches a handler for when a [`GuildUpdate`] is received. /// /// [`GuildUpdate`]: ../model/event/enum.Event.html#variant.GuildUpdate @@ -984,31 +921,6 @@ impl Client { .on_guild_update = Some(Arc::new(handler)); } - /// Attaches a handler for when a [`UserNoteUpdate`] is received. - /// - /// Optionally returns the old note for the [`User`], if one existed. - /// - /// [`User`]: ../model/struct.User.html - /// [`UserNoteUpdate`]: ../model/event/enum.Event.html#variant.UserNoteUpdate - pub fn on_note_update<F>(&mut self, handler: F) - where F: Fn(Context, UserId, Option<String>, String) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_note_update = Some(Arc::new(handler)); - } - - /// Attaches a handler for when a [`UserSettingsUpdate`] is received. - /// - /// The old user settings will be provided as well. - /// - /// [`UserSettingsUpdate`]: ../model/event/enum.Event.html#variant.UserSettingsUpdate - pub fn on_user_settings_update<F>(&mut self, handler: F) - where F: Fn(Context, UserSettings, UserSettings) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_user_settings_update = Some(Arc::new(handler)); - } - /// Attaches a handler for when a [`UserUpdate`] is received. /// /// The old current user will be provided as well. @@ -1110,16 +1022,6 @@ impl Client { .on_guild_role_update = Some(Arc::new(handler)); } - /// Attaches a handler for when a [`UserGuildSettingsUpdate`] is received. - /// - /// [`UserGuildSettingsUpdate`]: ../model/event/enum.Event.html#variant.UserGuildSettingsUpdate - pub fn on_user_guild_settings_update<F>(&mut self, handler: F) - where F: Fn(Context, UserGuildSettings) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_user_guild_settings_update = Some(Arc::new(handler)); - } - /// Attaches a handler for when a [`GuildUpdate`] is received. /// /// [`GuildUpdate`]: ../model/event/enum.Event.html#variant.GuildUpdate @@ -1130,29 +1032,6 @@ impl Client { .on_guild_update = Some(Arc::new(handler)); } - /// Attaches a handler for when a [`UserNoteUpdate`] is received. - /// - /// Optionally returns the old note for the [`User`], if one existed. - /// - /// [`User`]: ../model/struct.User.html - /// [`UserNoteUpdate`]: ../model/event/enum.Event.html#variant.UserNoteUpdate - pub fn on_note_update<F>(&mut self, handler: F) - where F: Fn(Context, UserId, String) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_note_update = Some(Arc::new(handler)); - } - - /// Attaches a handler for when a [`UserSettingsUpdate`] is received. - /// - /// [`UserSettingsUpdate`]: ../model/event/enum.Event.html#variant.UserSettingsUpdate - pub fn on_user_settings_update<F>(&mut self, handler: F) - where F: Fn(Context, UserSettingsUpdateEvent) + Send + Sync + 'static { - self.event_store.write() - .unwrap() - .on_user_settings_update = Some(Arc::new(handler)); - } - /// Attaches a handler for when a [`UserUpdate`] is received. /// /// [`UserUpdate`]: ../model/event/enum.Event.html#variant.UserUpdate @@ -1166,7 +1045,6 @@ impl Client { struct BootInfo { gateway_url: Arc<Mutex<String>>, - login_type: LoginType, shard_info: Option<[u64; 2]>, token: String, } @@ -1177,7 +1055,6 @@ struct MonitorInfo { event_store: Arc<RwLock<EventStore>>, framework: Arc<Mutex<Framework>>, gateway_url: Arc<Mutex<String>>, - login_type: LoginType, receiver: Receiver<WebSocketStream>, shard: Arc<Mutex<Shard>>, shard_info: Option<[u64; 2]>, @@ -1189,7 +1066,6 @@ struct MonitorInfo { data: Arc<Mutex<ShareMap>>, event_store: Arc<RwLock<EventStore>>, gateway_url: Arc<Mutex<String>>, - login_type: LoginType, receiver: Receiver<WebSocketStream>, shard: Arc<Mutex<Shard>>, shard_info: Option<[u64; 2]>, @@ -1220,8 +1096,7 @@ fn boot_shard(info: &BootInfo) -> Result<(Shard, ReadyEvent, Receiver<WebSocketS let attempt = Shard::new(&info.gateway_url.lock().unwrap(), &info.token, - info.shard_info, - info.login_type); + info.shard_info); match attempt { Ok((shard, ready, receiver)) => { @@ -1253,7 +1128,6 @@ fn monitor_shard(mut info: MonitorInfo) { for _ in 0..3 { let boot = boot_shard(&BootInfo { gateway_url: info.gateway_url.clone(), - login_type: info.login_type, shard_info: info.shard_info, token: info.token.clone(), }); @@ -1275,13 +1149,11 @@ fn monitor_shard(mut info: MonitorInfo) { &info.shard, &info.framework, &info.data, - info.login_type, &info.event_store); } else { dispatch(Event::Ready(ready), &info.shard, &info.data, - info.login_type, &info.event_store); }} @@ -1352,19 +1224,17 @@ fn handle_shard(info: &mut MonitorInfo) { &info.shard, &info.framework, &info.data, - info.login_type, &info.event_store); } else { dispatch(event, &info.shard, &info.data, - info.login_type, &info.event_store); }} } } -fn login(token: String, login_type: LoginType) -> Client { +fn login(token: String) -> Client { rest::set_token(&token); feature_framework! {{ @@ -1372,14 +1242,12 @@ fn login(token: String, login_type: LoginType) -> Client { data: Arc::new(Mutex::new(ShareMap::custom())), event_store: Arc::new(RwLock::new(EventStore::default())), framework: Arc::new(Mutex::new(Framework::default())), - login_type: login_type, token: token, } } else { Client { data: Arc::new(Mutex::new(ShareMap::custom())), event_store: Arc::new(RwLock::new(EventStore::default())), - login_type: login_type, token: token, } }} diff --git a/src/client/rest/mod.rs b/src/client/rest/mod.rs index c341bf2..8757114 100644 --- a/src/client/rest/mod.rs +++ b/src/client/rest/mod.rs @@ -45,7 +45,7 @@ use std::default::Default; use std::fmt::Write as FmtWrite; use std::io::{ErrorKind as IoErrorKind, Read}; use std::sync::{Arc, Mutex}; -use ::constants::{self, ErrorCode}; +use ::constants; use ::internal::prelude::*; use ::model::*; use ::utils::{decode_array, into_array}; @@ -82,24 +82,6 @@ pub fn set_token(token: &str) { TOKEN.lock().unwrap().clone_from(&token.to_owned()); } -/// Marks a [`Channel`] as being "read" up to a certain [`Message`]. Any -/// message past the given one will not be marked as read. -/// -/// Usually you should use this to mark the latest message as being read. -/// -/// **Note**: Bot users should not use this, as it has no bearing on them -/// whatsoever. -/// -/// [`Channel`]: ../../model/enum.Channel.html -/// [`Message`]: ../../model/struct.Message.html -pub fn ack_message(channel_id: u64, message_id: u64) -> Result<()> { - verify(204, request!(Route::ChannelsIdMessagesIdAck(channel_id), - post, - "/channels/{}/messages/{}/ack", - channel_id, - message_id)) -} - /// Adds a [`User`] as a recipient to a [`Group`]. /// /// **Note**: Groups have a limit of 10 recipients, including the current user. @@ -214,10 +196,9 @@ pub fn create_emoji(guild_id: u64, map: &Value) -> Result<Emoji> { /// Only a [`PartialGuild`] will be immediately returned, and a full [`Guild`] /// will be received over a [`Shard`], if at least one is running. /// -/// **Note**: This endpoint is usually only available for user accounts. Refer -/// to Discord's documentation for the endpoint [here][whitelist] for more -/// information. If your bot requires this, re-think what you are doing and -/// whether it _really_ needs to be doing this. +/// **Note**: This endpoint is currently limited to 10 active guilds. The +/// limits are raised for whitelisted [GameBridge] applications. See the +/// [documentation on this endpoint] for more info. /// /// # Examples /// @@ -241,7 +222,9 @@ pub fn create_emoji(guild_id: u64, map: &Value) -> Result<Emoji> { /// [`Guild`]: ../../model/struct.Guild.html /// [`PartialGuild`]: ../../model/struct.PartialGuild.html /// [`Shard`]: ../gateway/struct.Shard.html +/// [GameBridge]: https://discordapp.com/developers/docs/topics/gamebridge /// [US West Region]: ../../model/enum.Region.html#variant.UsWest +/// [documentation on this endpoint]: https://discordapp.com/developers/docs/resources/guild#create-guild /// [whitelist]: https://discordapp.com/developers/docs/resources/guild#create-guild pub fn create_guild(map: &Value) -> Result<PartialGuild> { let body = map.to_string(); @@ -517,8 +500,8 @@ pub fn delete_role(guild_id: u64, role_id: u64) -> Result<()> { /// use std::env; /// /// // Due to the `delete_webhook` function requiring you to authenticate, you -/// // must have initialized a client first. -/// let client = Client::login_user(&env::var("DISCORD_TOKEN").unwrap()); +/// // must have set the token first. +/// rest::set_token(&env::var("DISCORD_TOKEN").unwrap()); /// /// rest::delete_webhook(245037420704169985).expect("Error deleting webhook"); /// ``` @@ -641,16 +624,6 @@ pub fn edit_nickname(guild_id: u64, new_nickname: Option<&str>) -> Result<()> { verify(200, response) } -/// Changes a profile note. -pub fn edit_note(user_id: u64, map: &Value) -> Result<()> { - let body = map.to_string(); - - verify(204, request!(Route::None, - put(body), - "/users/@me/notes/{}", - user_id)) -} - /// Edits the current user's profile settings. /// /// For bot users, the password is optional. @@ -1271,14 +1244,6 @@ pub fn get_user(user_id: u64) -> Result<User> { User::decode(serde_json::from_reader(response)?) } -/// Gets our connections. -pub fn get_user_connections() -> Result<Vec<UserConnection>> { - let response = request!(Route::UsersMeConnections, get, "/users/@me/connections"); - - decode_array(serde_json::from_reader(response)?, - UserConnection::decode) -} - /// Gets our DM channels. pub fn get_user_dm_channels() -> Result<Vec<PrivateChannel>> { let response = request!(Route::UsersMeChannels, get, "/users/@me/channels"); @@ -1380,67 +1345,6 @@ pub fn remove_group_recipient(group_id: u64, user_id: u64) -> Result<()> { user_id)) } -/// Searches a [`Channel`] for [`Message`]s that meet provided requirements. -/// -/// **Note**: Bot users can not search. -/// -/// [`Channel`]: ../../model/enum.Channel.html -/// [`Message`]: ../../model/struct.Message.html -pub fn search_channel_messages(channel_id: u64, map: BTreeMap<&str, Value>) - -> Result<SearchResult> { - let mut uri = format!("/channels/{}/messages/search?", channel_id); - - for (k, v) in map { - let _ = write!(uri, "&{}={}", k, v); - } - - let response = request!(Route::ChannelsIdMessagesSearch(channel_id), - get, - "{}", - uri); - - if response.status == StatusCode::Accepted { - return Err(Error::Client(ClientError::ErrorCode(ErrorCode::SearchIndexUnavailable))); - } - - let content = try!(serde_json::from_reader(response)); - - SearchResult::decode(content) -} - -/// Searches a [`Guild`] - and optionally specific [channel][`GuildChannel`]s -/// within it - for messages that meet provided requirements. -/// -/// **Note**: Bot users can not search. -/// -/// [`Guild`]: ../../model/struct.Guild.html -/// [`GuildChannel`]: ../../model/struct.GuildChannel.html -pub fn search_guild_messages(guild_id: u64, - channel_ids: &[u64], - map: BTreeMap<&str, Value>) - -> Result<SearchResult> { - let mut uri = format!("/guilds/{}/messages/search?", guild_id); - - for (k, v) in map { - let _ = write!(uri, "&{}={}", k, v); - } - - for channel_id in channel_ids { - write!(uri, "&channel_id={}", channel_id)?; - } - - let response = request!(Route::GuildsIdMessagesSearch(guild_id), - get, - "{}", - uri); - - if response.status == StatusCode::Accepted { - return Err(Error::Client(ClientError::ErrorCode(ErrorCode::SearchIndexUnavailable))); - } - - SearchResult::decode(try!(serde_json::from_reader(response))) -} - /// Sends a file to a channel. pub fn send_file<R: Read>(channel_id: u64, mut file: R, diff --git a/src/client/rest/ratelimiting.rs b/src/client/rest/ratelimiting.rs index 00c374f..c8849eb 100644 --- a/src/client/rest/ratelimiting.rs +++ b/src/client/rest/ratelimiting.rs @@ -159,12 +159,6 @@ pub enum Route { /// /// [`ChannelId`]: ../../model/struct.ChannelId.html ChannelsIdMessagesIdReactionsUserIdType(u64), - /// Route for the `/channels/:channel_id/messages/search` path. - /// - /// The data is the relevant [`ChannelId`]. - /// - /// [`ChannelId`]: ../../model/struct.ChannelId.html - ChannelsIdMessagesSearch(u64), /// Route for the `/channels/:channel_id/permissions/:target_id` path. /// /// The data is the relevant [`ChannelId`]. @@ -292,12 +286,6 @@ pub enum Route { /// /// [`GuildId`]: struct.GuildId.html GuildsIdMembersMeNick(u64), - /// Route for the `/guilds/:guild_id/messages/search` path. - /// - /// The data is the relevant [`GuildId`]. - /// - /// [`GuildId`]: struct.GuildId.html - GuildsIdMessagesSearch(u64), /// Route for the `/guilds/:guild_id/prune` path. /// /// The data is the relevant [`GuildId`]. @@ -336,8 +324,6 @@ pub enum Route { UsersMe, /// Route for the `/users/@me/channels` path. UsersMeChannels, - /// Route for the `/users/@me/connections` path. - UsersMeConnections, /// Route for the `/users/@me/guilds` path. UsersMeGuilds, /// Route for the `/users/@me/guilds/:guild_id` path. diff --git a/src/ext/cache/mod.rs b/src/ext/cache/mod.rs index ad0ef31..7bb9dd8 100644 --- a/src/ext/cache/mod.rs +++ b/src/ext/cache/mod.rs @@ -49,19 +49,6 @@ //! while needing to hit the REST API as little as possible, then the answer //! is "yes". //! -//! # Special cases in the Cache -//! -//! Some items in the cache, notably [`Call`]s and [`Group`]s, will "always be -//! empty". The exception to this rule, is for: -//! -//! 1. Bots which used to be userbots prior to the conversion made available by -//! Discord when the official Bot API was introduced; -//! 2. For groups and calls: -//! 2a. Bots that have friends from before the conversion that have not been -//! removed, as those users can still add the bots to groups; -//! 2b. Bots that have the "Create Group" endpoint whitelisted specifically for -//! them. -//! //! [`Call`]: ../../model/struct.Call.html //! [`Context`]: ../../client/struct.Context.html //! [`Context::get_channel`]: ../../client/struct.Context.html#method.get_channel @@ -143,10 +130,6 @@ pub struct Cache { /// /// [special cases]: index.html#special-cases-in-the-cache pub groups: HashMap<ChannelId, Arc<RwLock<Group>>>, - /// Settings specific to a guild. - /// - /// This will always be empty for bot users. - pub guild_settings: HashMap<Option<GuildId>, UserGuildSettings>, /// A map of guilds with full data available. This includes data like /// [`Role`]s and [`Emoji`]s that are not available through the REST API. /// @@ -167,14 +150,6 @@ pub struct Cache { /// A map of direct message channels that the current user has open with /// other users. pub private_channels: HashMap<ChannelId, Arc<RwLock<PrivateChannel>>>, - /// A map of relationships that the current user has with other users. - /// - /// For bot users this will always be empty, except for in [special cases]. - /// - /// [special cases]: index.html#special-cases-in-the-cache - pub relationships: HashMap<UserId, Relationship>, - /// Account-specific settings for a user account. - pub settings: Option<UserSettings>, /// A list of guilds which are "unavailable". Refer to the documentation for /// [`Event::GuildUnavailable`] for more information on when this can occur. /// @@ -969,12 +944,6 @@ impl Cache { } } - if let Some(user_guild_settings) = ready.user_guild_settings { - for guild in user_guild_settings { - self.guild_settings.insert(guild.guild_id, guild); - } - } - for (user_id, presence) in &mut ready.presences { if let Some(ref user) = presence.user { self.update_user_entry(&user.read().unwrap()); @@ -984,69 +953,10 @@ impl Cache { } self.presences.extend(ready.presences); - self.relationships.extend(ready.relationships); - self.notes.extend(ready.notes); - self.settings = ready.user_settings; self.user = ready.user; } #[doc(hidden)] - pub fn update_with_relationship_add(&mut self, event: &RelationshipAddEvent) { - self.update_user_entry(&event.relationship.user); - - self.relationships.insert(event.relationship.id, event.relationship.clone()); - } - - #[doc(hidden)] - pub fn update_with_relationship_remove(&mut self, event: &RelationshipRemoveEvent) { - self.relationships.remove(&event.user_id); - } - - #[doc(hidden)] - pub fn update_with_user_guild_settings_update(&mut self, event: &UserGuildSettingsUpdateEvent) - -> Option<UserGuildSettings> { - self.guild_settings - .get_mut(&event.settings.guild_id) - .map(|guild_setting| mem::replace(guild_setting, event.settings.clone())) - } - - #[doc(hidden)] - pub fn update_with_user_note_update(&mut self, event: &UserNoteUpdateEvent) -> Option<String> { - if event.note.is_empty() { - self.notes.remove(&event.user_id) - } else { - self.notes.insert(event.user_id, event.note.clone()) - } - } - - #[doc(hidden)] - pub fn update_with_user_settings_update(&mut self, event: &UserSettingsUpdateEvent, old: bool) - -> Option<UserSettings> { - let item = if old { - self.settings.clone() - } else { - None - }; - - self.settings - .as_mut() - .map(|settings| { - opt_modify(&mut settings.enable_tts_command, &event.enable_tts_command); - opt_modify(&mut settings.inline_attachment_media, &event.inline_attachment_media); - opt_modify(&mut settings.inline_embed_media, &event.inline_embed_media); - opt_modify(&mut settings.locale, &event.locale); - opt_modify(&mut settings.message_display_compact, &event.message_display_compact); - opt_modify(&mut settings.render_embeds, &event.render_embeds); - opt_modify(&mut settings.show_current_game, &event.show_current_game); - opt_modify(&mut settings.theme, &event.theme); - opt_modify(&mut settings.convert_emoticons, &event.convert_emoticons); - opt_modify(&mut settings.friend_source_flags, &event.friend_source_flags); - }); - - item - } - - #[doc(hidden)] pub fn update_with_user_update(&mut self, event: &UserUpdateEvent) -> CurrentUser { mem::replace(&mut self.user, event.current_user.clone()) } @@ -1126,13 +1036,10 @@ impl Default for Cache { calls: HashMap::default(), channels: HashMap::default(), groups: HashMap::default(), - guild_settings: HashMap::default(), guilds: HashMap::default(), notes: HashMap::default(), presences: HashMap::default(), private_channels: HashMap::default(), - relationships: HashMap::default(), - settings: None, unavailable_guilds: HashSet::default(), user: CurrentUser { avatar: None, @@ -1141,7 +1048,6 @@ impl Default for Cache { email: None, id: UserId(0), mfa_enabled: false, - mobile: None, name: String::default(), verified: false, }, @@ -1149,9 +1055,3 @@ impl Default for Cache { } } } - -fn opt_modify<T: Clone>(dest: &mut T, src: &Option<T>) { - if let Some(val) = src.as_ref() { - dest.clone_from(val); - } -} diff --git a/src/ext/framework/configuration.rs b/src/ext/framework/configuration.rs index 0fd18c2..b5c58c9 100644 --- a/src/ext/framework/configuration.rs +++ b/src/ext/framework/configuration.rs @@ -41,7 +41,7 @@ pub enum AccountType { /// use serenity::Client; /// use std::env; /// -/// let mut client = Client::login_bot(&env::var("DISCORD_BOT_TOKEN").unwrap()); +/// let mut client = Client::login(&env::var("DISCORD_BOT_TOKEN").unwrap()); /// /// client.with_framework(|f| f /// .configure(|c| c.on_mention(true).prefix("~"))); diff --git a/src/ext/framework/create_command.rs b/src/ext/framework/create_command.rs index 68319af..7f2c25f 100644 --- a/src/ext/framework/create_command.rs +++ b/src/ext/framework/create_command.rs @@ -45,7 +45,7 @@ impl CreateCommand { /// use serenity::model::Message; /// use std::env; /// - /// let mut client = Client::login_bot(&env::var("DISCORD_TOKEN").unwrap()); + /// let mut client = Client::login(&env::var("DISCORD_TOKEN").unwrap()); /// /// client.with_framework(|f| f /// .configure(|c| c.prefix("~")) diff --git a/src/ext/framework/help_commands.rs b/src/ext/framework/help_commands.rs index 4f16773..cee0e5e 100644 --- a/src/ext/framework/help_commands.rs +++ b/src/ext/framework/help_commands.rs @@ -10,7 +10,7 @@ //! use serenity::Client; //! use std::env; //! -//! let mut client = Client::login_bot(&env::var("DISCORD_TOKEN").unwrap()); +//! let mut client = Client::login(&env::var("DISCORD_TOKEN").unwrap()); //! client.with_framework(|f| f //! .command("help", |c| c.exec_help(help_commands::with_embeds))); //! ``` diff --git a/src/ext/framework/mod.rs b/src/ext/framework/mod.rs index 552ab93..098f26a 100644 --- a/src/ext/framework/mod.rs +++ b/src/ext/framework/mod.rs @@ -36,7 +36,7 @@ //! use serenity::model::Message; //! use std::env; //! -//! let mut client = Client::login_bot(&env::var("DISCORD_BOT_TOKEN").unwrap()); +//! let mut client = Client::login(&env::var("DISCORD_BOT_TOKEN").unwrap()); //! //! client.with_framework(|f| f //! .configure(|c| c.prefix("~")) @@ -74,11 +74,13 @@ use std::default::Default; use std::sync::Arc; use std::thread; use ::client::Context; -use ::model::{Channel, Message, UserId}; +use ::model::{Message, UserId}; use ::utils; #[cfg(feature="cache")] use ::client::CACHE; +#[cfg(feature="cache")] +use ::model::Channel; /// A macro to generate "named parameters". This is useful to avoid manually /// using the "arguments" parameter and manually parsing types. @@ -214,7 +216,7 @@ impl Framework { /// use serenity::Client; /// use std::env; /// - /// let mut client = Client::login_bot(&env::var("DISCORD_TOKEN").unwrap()); + /// let mut client = Client::login(&env::var("DISCORD_TOKEN").unwrap()); /// client.with_framework(|f| f /// .configure(|c| c /// .depth(3) @@ -696,7 +698,7 @@ impl Framework { /// use serenity::model::Message; /// use std::env; /// - /// let mut client = Client::login_bot(&env::var("DISCORD_TOKEN").unwrap()); + /// let mut client = Client::login(&env::var("DISCORD_TOKEN").unwrap()); /// /// client.with_framework(|f| f /// .configure(|c| c.prefix("~")) @@ -2,8 +2,7 @@ //! //! View the [examples] on how to make and structure a bot. //! -//! Serenity supports both bot and user login via the use of [`Client::login_bot`] -//! and [`Client::login_user`]. +//! Serenity supports bot user authentication via the use of [`Client::login`]. //! //! Once logged in, you may add handlers to your client to dispatch [`Event`]s, //! such as [`Client::on_message`]. This will cause your handler to be called @@ -38,7 +37,7 @@ //! //! fn main() { //! // Login with a bot token from the environment -//! let mut client = Client::login_bot(&env::var("DISCORD_TOKEN").expect("token")); +//! let mut client = Client::login(&env::var("DISCORD_TOKEN").expect("token")); //! client.with_framework(|f| f //! .configure(|c| c.prefix("~")) // set the bot's prefix to "~" //! .on("ping", ping)); @@ -73,8 +72,7 @@ //! ``` //! //! [`Cache`]: ext/cache/struct.Cache.html -//! [`Client::login_bot`]: client/struct.Client.html#method.login_bot -//! [`Client::login_user`]: client/struct.Client.html#method.login_user +//! [`Client::login`]: client/struct.Client.html#method.login //! [`Client::on_message`]: client/struct.Client.html#method.on_message //! [`Context`]: client/struct.Context.html //! [`Event`]: model/event/enum.Event.html 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)?; diff --git a/src/utils/builder/create_invite.rs b/src/utils/builder/create_invite.rs index b3592d0..99125b3 100644 --- a/src/utils/builder/create_invite.rs +++ b/src/utils/builder/create_invite.rs @@ -15,7 +15,7 @@ use std::default::Default; /// use serenity::Client; /// use std::env; /// -/// let mut client = Client::login_bot(&env::var("DISCORD_BOT_TOKEN").unwrap()); +/// let mut client = Client::login(&env::var("DISCORD_BOT_TOKEN").unwrap()); /// /// client.on_message(|_, message| { /// if message.content == "!invite" { diff --git a/src/utils/builder/mod.rs b/src/utils/builder/mod.rs index 10a20d9..3fc0f05 100644 --- a/src/utils/builder/mod.rs +++ b/src/utils/builder/mod.rs @@ -15,7 +15,6 @@ mod edit_profile; mod edit_role; mod execute_webhook; mod get_messages; -mod search; pub use self::create_embed::{ CreateEmbed, @@ -32,4 +31,3 @@ pub use self::edit_profile::EditProfile; pub use self::edit_role::EditRole; pub use self::execute_webhook::ExecuteWebhook; pub use self::get_messages::GetMessages; -pub use self::search::{Search, Has}; diff --git a/src/utils/builder/search.rs b/src/utils/builder/search.rs deleted file mode 100644 index 5a4d4a9..0000000 --- a/src/utils/builder/search.rs +++ /dev/null @@ -1,319 +0,0 @@ -use serde_json::Value; -use std::collections::BTreeMap; -use ::model::{MessageId, UserId}; - -/// An indicator for filtering [`Message`]s that have a certain item or quality. -/// -/// Used with [`Search::has`]. -/// -/// [`Message`]: ../../model/struct.Message.html -/// [`Search::has`]: struct.Search.html#method.has -pub enum Has { - /// Find messages that have an [`Embed`]. - /// - /// [`Embed`]: ../../model/struct.Embed.html - Embed, - /// Find messages that have an [`Attachment`]. - /// - /// [`Attachment`]: ../../model/struct.Attachment.html - File, - /// Find messages that have an embed with an image. - Image, - /// Find messages with a link of any kind. - Link, - /// Find messages that have an [`Embed`] with a sound [`provider`]. - /// - /// [`Embed`]: ../../model/struct.Embed.html - /// [`provider`]: ../../model/struct.Embed.html#structfield.provider - Sound, - /// Find messages that have an [`Embed`] with a `video` - /// [type][`Embed::kind`]. - /// - /// [`Embed`]: ../../model/struct.Embed.html - /// [`Embed::kind`]: ../../model/struct.Embed.html#structfield.kind - Video, -} - -impl Has { - /// Returns the "name" of the variant. - #[doc(hidden)] - pub fn name(&self) -> &str { - use self::Has::*; - - match *self { - Embed => "embed", - File => "file", - Image => "image", - Link => "link", - Sound => "sound", - Video => "video", - } - } -} - -/// A builder used to query a [`Channel`] or [`Guild`] for its [`Message`]s, -/// specifying certain parameters to narrow down the returned messages. -/// -/// Many methods are provided to narrow down the results, such as [`limit`], -/// which can be used in conjunction with [`offset`] to paginate results. -/// -/// # Examples -/// -/// Provided are multiple in-depth examples for searching through different -/// means. Also see [example 08] for a fully runnable selfbot. -/// -/// ### Searching a Channel -/// -/// Search for messages via [`Channel::search`] with the content `"rust"`, which -/// have an embed, have a video, and limiting to 5 results: -/// -/// ```rust,ignore -/// use serenity::utils::builder::Has; -/// -/// // assuming a `channel` has been bound -/// -/// let search = channel.search(|s| s -/// .content("rust") -/// .has(vec![Has::Embed, Has::Video]) -/// .limit(5)); -/// ``` -/// -/// ### Searching a Guild's Channels -/// -/// Search for messages with a query provided by a user, which have an -/// embed, have no attachment, searching by timestamp in descending order, -/// limiting to 2 results, and only searching channels that have a name -/// prefixed with `"search-"`: -/// -/// ```rust,ignore -/// use serenity::client::{Client, Context}; -/// use serenity::model::Message; -/// use std::env; -/// -/// let mut client = Client::login_bot(&env::var("DISCORD_BOT_TOKEN").unwrap()); -/// -/// client.with_framework(|f| f -/// .configure(|c| c.prefix("~").on_mention(true)) -/// .on("search", search)); -/// -/// command!(search(ctx, msg, args) { -/// let query = args.join(" "); -/// -/// if query.is_empty() { -/// let _ = msg.channel_id.say("You must provide a query"); -/// -/// return Ok(()); -/// } -/// -/// let guild = msg.guild().unwrap(); -/// -/// let channel_ids = guild -/// .channels -/// .values() -/// .filter(|c| c.name.starts_with("search-")) -/// .map(|c| c.id) -/// .collect(); -/// -/// let search = guild.search(guild.id, channel_ids, |s| s -/// .content(&query) -/// .context_size(0) -/// .has_attachment(true) -/// .has_embed(true) -/// .max_id(msg.id.0 - 1)) -/// .unwrap(); -/// -/// let _ = msg.channel_id.send_message(|m| m -/// .content(&format!("Found {} total results", messages.total)) -/// .embed(|mut e| { -/// for (i, messages) in messages.results.iter_mut().enumerate() { -/// let mut found = match messages.get_mut(i) { -/// Some(found) => found, -/// None => break, -/// }; -/// -/// found.content.truncate(1000); -/// -/// e = e.field(|f| f -/// .name(&format!("Result {}", i)) -/// .value(&found.content)); -/// } -/// -/// e -/// })); -/// }); -/// ``` -/// -/// [`Channel`]: ../../model/enum.Channel.html -/// [`Context::search_channel`]: ../../client/struct.Context.html#method.search_channel -/// [`Guild`]: ../../model/struct.Guild.html -/// [`Message`]: ../../model/struct.Message.html -/// [`limit`]: #method.limit -/// [`offset`]: #method.offset -/// [example 08]: https://github.com/zeyla/serenity/tree/master/examples/08_search -pub struct Search(pub BTreeMap<&'static str, Value>); - -impl Search { - /// Filters [`Message`]s by the the Id of the author. - /// - /// [`Message`]: ../../model/struct.Message.html - pub fn author_id<U: Into<UserId>>(mut self, author_id: U) -> Self { - self.0.insert("author_id", Value::U64(author_id.into().0)); - - self - } - - /// Filtes [`Message`] by content. This is a fuzzy search, and can partially - /// match the given query content. - /// - /// [`Message`]: ../../model/struct.Message.html - pub fn content<S: Into<String>>(mut self, content: S) -> Self { - self.0.insert("content", Value::String(content.into())); - - self - } - - /// Sets the amount of "contextual" [`Message`]s to provide, at maximum. - /// This is the number of messages to provide around each side - /// (ascending+descending) of the "hit" (aka found) message. - /// - /// The number of returned contextual messages can be lower if there are - /// fewer messages in the order. - /// - /// The default value is `2`. The minimum value is `0`. The maximum value is - /// `2`. - /// - /// [`Message`]: ../../model/struct.Message.html - pub fn context_size(mut self, mut context_size: u8) -> Self { - if context_size > 2 { - context_size = 2; - } - - self.0.insert("context_size", Value::U64(context_size as u64)); - - self - } - - /// Filter [`Message`]s by whether they have a certain item. - /// - /// You can pass either one or more [`Has`] variants. - /// - /// # Examples - /// - /// Passing a single variant: - /// - /// ```rust,no_run - /// use serenity::model::ChannelId; - /// use serenity::utils::builder::Has; - /// - /// let _ = ChannelId(7).search(|s| s.has(vec![Has::Embed])); - /// ``` - /// - /// Passing multiple: - /// - /// ```rust,no_run - /// use serenity::model::ChannelId; - /// use serenity::utils::builder::Has; - /// - /// let _ = ChannelId(7).search(|s| s.has(vec![Has::Embed, Has::Sound])); - /// ``` - /// - /// [`Has`]: enum.Has.html - /// [`Message`]: ../../model/struct.Message.html - pub fn has(mut self, has: Vec<Has>) -> Self { - let names = has.into_iter().map(|h| Value::String(h.name().to_owned())).collect(); - self.0.insert("has", Value::Array(names)); - - self - } - - /// Sets the number of messages to retrieve _at maximum_. This can be used - /// in conjunction with [`offset`]. - /// - /// The minimum value is `1`. The maximum value is `25`. - /// - /// [`offset`]: #method.offset - pub fn limit(mut self, limit: u8) -> Self { - self.0.insert("limit", Value::U64(limit as u64)); - - self - } - - /// Set the maximum [`Message`] Id to search up to. All messages with an Id - /// greater than the given value will be ignored. - /// - /// [`Message`]: ../../model/struct.Message.html - pub fn max_id<M: Into<MessageId>>(mut self, message_id: M) -> Self { - self.0.insert("max_id", Value::U64(message_id.into().0)); - - self - } - - /// Filter [`Message`]s by whether they mention one or more specific - /// [`User`]s. - /// - /// This is an OR statement. - /// - /// # Examples - /// - /// Search for only one mention: - /// - /// ```rust,no_run - /// use serenity::model::{ChannelId, UserId}; - /// - /// let _ = ChannelId(7).search(|s| s.mentions(vec![UserId(8)])); - /// ``` - /// - /// Search for two mentions: - /// - /// ```rust,no_run - /// use serenity::model::{ChannelId, UserId}; - /// - /// let _ = ChannelId(7).search(|s| s.mentions(vec![UserId(8), UserId(9)])); - /// ``` - /// - /// [`Message`]: ../../model/struct.Message.html - /// [`User`]: ../../model/struct.User.html - pub fn mentions(mut self, mentions: Vec<UserId>) -> Self { - let ids = mentions.into_iter().map(|m| Value::U64(m.0)).collect(); - self.0.insert("mentions", Value::Array(ids)); - - self - } - - /// Set the minimum [`Message`]s Id to search down to. All messages with an - /// Id less than the given value will be ignored. - /// - /// [`Message`]: ../../model/struct.Message.html - pub fn min_id<M: Into<MessageId>>(mut self, message_id: M) -> Self { - self.0.insert("min_id", Value::U64(message_id.into().0)); - - self - } - - /// Set the offset of [`Message`]s to return. This can be used in - /// conjunction with [`limit`]. - /// - /// The minimum value is `0`. The maximum value is `5000`. - /// - /// [`Message`]: ../../model/struct.Message.html - /// [`limit`]: #method.limit - pub fn offset(mut self, offset: u16) -> Self { - self.0.insert("offset", Value::U64(offset as u64)); - - self - } -} - -impl Default for Search { - /// Creates a new builder for searching for [`Message`]s. Refer to each - /// method to learn what minimum and maximum values are available for each - /// field, as well as restrictions and other useful information. - /// - /// The library does not provide defaults differently than what Discord - /// itself defaults to. - /// - /// [`Message`]: ../../model/struct.Message.html - fn default() -> Search { - Search(BTreeMap::default()) - } -} |