diff options
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/context.rs | 11 | ||||
| -rw-r--r-- | src/client/dispatch.rs | 2 | ||||
| -rw-r--r-- | src/client/event_store.rs | 54 | ||||
| -rw-r--r-- | src/client/gateway/prep.rs | 4 | ||||
| -rw-r--r-- | src/client/gateway/shard.rs | 2 | ||||
| -rw-r--r-- | src/client/mod.rs | 12 |
6 files changed, 47 insertions, 38 deletions
diff --git a/src/client/context.rs b/src/client/context.rs index eb7246b..e646ec6 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -22,7 +22,7 @@ use ::internal::prelude::*; use ::model::*; use ::utils; -#[cfg(feature = "cache")] +#[cfg(feature="cache")] use super::CACHE; /// The context is a general utility struct provided on event dispatches, which @@ -1077,6 +1077,15 @@ impl Context { Ok(channels) } + /// Gets information about the current user. + /// + /// Note this is shorthand for retrieving the current user through the + /// cache, and will perform a clone. + #[cfg(all(feature = "cache", feature = "methods"))] + pub fn get_current_user(&self) -> CurrentUser { + CACHE.read().unwrap().user.clone() + } + /// Gets an [`Guild`]'s emoji by Id. /// /// Requires the [Manage Emojis] permission. diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 7b0439d..5f61ea9 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -11,7 +11,7 @@ use ::model::{ChannelId, Message}; #[cfg(feature="framework")] use ::ext::framework::Framework; -#[cfg(feature = "cache")] +#[cfg(feature="cache")] use super::CACHE; macro_rules! handler { diff --git a/src/client/event_store.rs b/src/client/event_store.rs index e2ddf94..7cc7e81 100644 --- a/src/client/event_store.rs +++ b/src/client/event_store.rs @@ -14,7 +14,7 @@ use ::model::event::{ }; use ::model::*; -#[cfg(not(feature = "cache"))] +#[cfg(not(feature="cache"))] use ::model::event::{ CallUpdateEvent, GuildMemberUpdateEvent, @@ -43,13 +43,13 @@ use ::model::event::{ #[derive(Default)] pub struct EventStore { pub on_call_create: Option<Arc<Fn(Context, Call) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_call_delete: Option<Arc<Fn(Context, ChannelId, Option<Call>) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_call_delete: Option<Arc<Fn(Context, ChannelId) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_call_update: Option<Arc<Fn(Context, Option<Call>, Option<Call>) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_call_update: Option<Arc<Fn(Context, CallUpdateEvent) + Send + Sync + 'static>>, pub on_channel_create: Option<Arc<Fn(Context, Channel) + Send + Sync + 'static>>, pub on_channel_delete: Option<Arc<Fn(Context, Channel) + Send + Sync + 'static>>, @@ -57,45 +57,45 @@ pub struct EventStore { pub on_channel_pins_update: Option<Arc<Fn(Context, ChannelPinsUpdateEvent) + Send + Sync + 'static>>, pub on_channel_recipient_addition: Option<Arc<Fn(Context, ChannelId, User) + Send + Sync + 'static>>, pub on_channel_recipient_removal: Option<Arc<Fn(Context, ChannelId, User) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_channel_update: Option<Arc<Fn(Context, Option<Channel>, Channel) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[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>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_guild_delete: Option<Arc<Fn(Context, PartialGuild, Option<Guild>) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_guild_delete: Option<Arc<Fn(Context, PartialGuild) + Send + Sync + 'static>>, pub on_guild_emojis_update: Option<Arc<Fn(Context, GuildId, HashMap<EmojiId, Emoji>) + Send + Sync + 'static>>, pub on_guild_integrations_update: Option<Arc<Fn(Context, GuildId) + Send + Sync + 'static>>, pub on_guild_member_addition: Option<Arc<Fn(Context, GuildId, Member) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_guild_member_removal: Option<Arc<Fn(Context, GuildId, User, Option<Member>) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_guild_member_removal: Option<Arc<Fn(Context, GuildId, User) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_guild_member_update: Option<Arc<Fn(Context, Option<Member>, Member) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_guild_member_update: Option<Arc<Fn(Context, GuildMemberUpdateEvent) + Send + Sync + 'static>>, pub on_guild_members_chunk: Option<Arc<Fn(Context, GuildId, HashMap<UserId, Member>) + Send + Sync + 'static>>, pub on_guild_role_create: Option<Arc<Fn(Context, GuildId, Role) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_guild_role_delete: Option<Arc<Fn(Context, GuildId, RoleId, Option<Role>) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_guild_role_delete: Option<Arc<Fn(Context, GuildId, RoleId) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_guild_role_update: Option<Arc<Fn(Context, GuildId, Option<Role>, Role) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_guild_role_update: Option<Arc<Fn(Context, GuildId, Role) + Send + Sync + 'static>>, pub on_guild_sync: Option<Arc<Fn(Context, GuildSyncEvent) + Send + Sync + 'static>>, pub on_guild_unavailable: Option<Arc<Fn(Context, GuildId) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_guild_update: Option<Arc<Fn(Context, Option<Guild>, PartialGuild) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_guild_update: Option<Arc<Fn(Context, PartialGuild) + Send + Sync + 'static>>, pub on_message: Option<Arc<Fn(Context, Message) + Send + Sync + 'static>>, pub on_message_ack: Option<Arc<Fn(Context, ChannelId, Option<MessageId>) + Send + Sync + 'static>>, @@ -105,9 +105,9 @@ 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")] + #[cfg(feature="cache")] pub on_note_update: Option<Arc<Fn(Context, UserId, Option<String>, String) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[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>>, @@ -117,17 +117,17 @@ pub struct EventStore { 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")] + #[cfg(feature="cache")] pub on_user_guild_settings_update: Option<Arc<Fn(Context, Option<UserGuildSettings>, UserGuildSettings) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_user_guild_settings_update: Option<Arc<Fn(Context, UserGuildSettings) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_user_update: Option<Arc<Fn(Context, CurrentUser, CurrentUser) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[cfg(not(feature="cache"))] pub on_user_update: Option<Arc<Fn(Context, CurrentUser) + Send + Sync + 'static>>, - #[cfg(feature = "cache")] + #[cfg(feature="cache")] pub on_user_settings_update: Option<Arc<Fn(Context, UserSettings, UserSettings) + Send + Sync + 'static>>, - #[cfg(not(feature = "cache"))] + #[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>>, diff --git a/src/client/gateway/prep.rs b/src/client/gateway/prep.rs index 3844a8d..4602ea6 100644 --- a/src/client/gateway/prep.rs +++ b/src/client/gateway/prep.rs @@ -80,12 +80,12 @@ pub fn identify(token: &str, shard_info: Option<[u8; 2]>) -> Value { .build() } -#[cfg(not(feature = "debug"))] +#[cfg(not(feature="debug"))] pub fn identify_compression(object: ObjectBuilder) -> ObjectBuilder { object.insert("compression", true) } -#[cfg(feature = "debug")] +#[cfg(feature="debug")] pub fn identify_compression(object: ObjectBuilder) -> ObjectBuilder { object.insert("compression", false) } diff --git a/src/client/gateway/shard.rs b/src/client/gateway/shard.rs index 232d2c3..c026f0c 100644 --- a/src/client/gateway/shard.rs +++ b/src/client/gateway/shard.rs @@ -69,7 +69,7 @@ pub struct Shard { ws_url: String, /// The voice connections that this Shard is responsible for. The Shard will /// update the voice connections' states. - #[cfg(feature = "voice")] + #[cfg(feature="voice")] pub manager: VoiceManager, } diff --git a/src/client/mod.rs b/src/client/mod.rs index 843bbfe..c9a9c65 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -61,20 +61,20 @@ use ::model::event::{ }; use ::model::*; -#[cfg(feature = "framework")] +#[cfg(feature="framework")] use ::ext::framework::Framework; -#[cfg(feature = "cache")] +#[cfg(feature="cache")] use ::ext::cache::Cache; -#[cfg(not(feature = "cache"))] +#[cfg(not(feature="cache"))] use ::model::event::{ CallUpdateEvent, GuildMemberUpdateEvent, UserSettingsUpdateEvent, }; -#[cfg(feature = "cache")] +#[cfg(feature="cache")] lazy_static! { /// A mutable and lazily-initialized static binding. It can be accessed /// across any function and in any context. @@ -841,7 +841,7 @@ impl Client { } } -#[cfg(feature = "cache")] +#[cfg(feature="cache")] impl Client { /// Attaches a handler for when a [`CallDelete`] is received. /// @@ -1003,7 +1003,7 @@ impl Client { } } -#[cfg(not(feature = "cache"))] +#[cfg(not(feature="cache"))] impl Client { /// Attaches a handler for when a [`CallDelete`] is received. /// |