aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-06-28 20:05:25 +0200
committeracdenisSK <[email protected]>2017-06-28 20:05:25 +0200
commite3db2f0f31cc294197997852e794c356a956909a (patch)
tree69a4b9a772a86119dca72fde4a90b46ceb724c4c /src
parentUpdate readme, docs and add `EventHandler` to the prelude (diff)
downloadserenity-e3db2f0f31cc294197997852e794c356a956909a.tar.xz
serenity-e3db2f0f31cc294197997852e794c356a956909a.zip
Whoops, and add a fail-safe to an upcomming pr to the compiler
https://github.com/rust-lang/rust/pull/42894
Diffstat (limited to 'src')
-rw-r--r--src/client/event_handler.rs94
-rw-r--r--src/client/event_store.rs95
-rw-r--r--src/client/mod.rs6
3 files changed, 50 insertions, 145 deletions
diff --git a/src/client/event_handler.rs b/src/client/event_handler.rs
index b233b8a..dd5186e 100644
--- a/src/client/event_handler.rs
+++ b/src/client/event_handler.rs
@@ -11,67 +11,67 @@ use std::sync::RwLock;
#[allow(type_complexity)]
pub trait EventHandler {
#[cfg(feature="cache")]
- fn on_cached(&self, Context, Vec<GuildId>) {}
- fn on_channel_create(&self, Context, Channel) {}
- fn on_channel_delete(&self, Context, Channel) {}
- fn on_channel_pins_update(&self, Context, ChannelPinsUpdateEvent) {}
- fn on_channel_recipient_addition(&self, Context, ChannelId, User) {}
- fn on_channel_recipient_removal(&self, Context, ChannelId, User) {}
+ fn on_cached(&self, _: Context, _: Vec<GuildId>) {}
+ fn on_channel_create(&self, _: Context, _: Channel) {}
+ fn on_channel_delete(&self, _: Context, _: Channel) {}
+ fn on_channel_pins_update(&self, _: Context, _: ChannelPinsUpdateEvent) {}
+ fn on_channel_recipient_addition(&self, _: Context, _: ChannelId, _: User) {}
+ fn on_channel_recipient_removal(&self, _: Context, _: ChannelId, _: User) {}
#[cfg(feature="cache")]
- fn on_channel_update(&self, Context, Option<Channel>, Channel) {}
+ fn on_channel_update(&self, _: Context, _: Option<Channel>, _: Channel) {}
#[cfg(not(feature="cache"))]
- fn on_channel_update(&self, Context, Channel) {}
- fn on_guild_ban_addition(&self, Context, GuildId, User) {}
- fn on_guild_ban_removal(&self, Context, GuildId, User) {}
- fn on_guild_create(&self, Context, Guild) {}
+ fn on_channel_update(&self, _: Context, _: Channel) {}
+ fn on_guild_ban_addition(&self, _: Context, _: GuildId, _: User) {}
+ fn on_guild_ban_removal(&self, _: Context, _: GuildId, _: User) {}
+ fn on_guild_create(&self, _: Context, _: Guild) {}
#[cfg(feature="cache")]
- fn on_guild_delete(&self, Context, PartialGuild, Option<Arc<RwLock<Guild>>>) {}
+ fn on_guild_delete(&self, _: Context, _: PartialGuild, _: Option<Arc<RwLock<Guild>>>) {}
#[cfg(not(feature="cache"))]
- fn on_guild_delete(&self, Context, PartialGuild) {}
- fn on_guild_emojis_update(&self, Context, GuildId, HashMap<EmojiId, Emoji>) {}
- fn on_guild_integrations_update(&self, Context, GuildId) {}
- fn on_guild_member_addition(&self, Context, GuildId, Member) {}
+ fn on_guild_delete(&self, _: Context, _: PartialGuild) {}
+ fn on_guild_emojis_update(&self, _: Context, _: GuildId, _: HashMap<EmojiId, Emoji>) {}
+ fn on_guild_integrations_update(&self, _: Context, _: GuildId) {}
+ fn on_guild_member_addition(&self, _: Context, _: GuildId, _: Member) {}
#[cfg(feature="cache")]
- fn on_guild_member_removal(&self, Context, GuildId, User, Option<Member>) {}
+ fn on_guild_member_removal(&self, _: Context, _: GuildId, _: User, _: Option<Member>) {}
#[cfg(not(feature="cache"))]
- fn on_guild_member_removal(&self, Context, GuildId, User) {}
+ fn on_guild_member_removal(&self, _: Context, _: GuildId, _: User) {}
#[cfg(feature="cache")]
- fn on_guild_member_update(&self, Context, Option<Member>, Member) {}
+ fn on_guild_member_update(&self, _: Context, _: Option<Member>, _: Member) {}
#[cfg(not(feature="cache"))]
- fn on_guild_member_update(&self, Context, GuildMemberUpdateEvent) {}
- fn on_guild_members_chunk(&self, Context, GuildId, HashMap<UserId, Member>) {}
- fn on_guild_role_create(&self, Context, GuildId, Role) {}
+ fn on_guild_member_update(&self, _: Context, _: GuildMemberUpdateEvent) {}
+ fn on_guild_members_chunk(&self, _: Context, _: GuildId, _: HashMap<UserId, Member>) {}
+ fn on_guild_role_create(&self, _: Context, _: GuildId, _: Role) {}
#[cfg(feature="cache")]
- fn on_guild_role_delete(&self, Context, GuildId, RoleId, Option<Role>) {}
+ fn on_guild_role_delete(&self, _: Context, _: GuildId, _: RoleId, _: Option<Role>) {}
#[cfg(not(feature="cache"))]
- fn on_guild_role_delete(&self, Context, GuildId, RoleId) {}
+ fn on_guild_role_delete(&self, _: Context, _: GuildId, _: RoleId) {}
#[cfg(feature="cache")]
- fn on_guild_role_update(&self, Context, GuildId, Option<Role>, Role) {}
+ fn on_guild_role_update(&self, _: Context, _: GuildId, _: Option<Role>, _: Role) {}
#[cfg(not(feature="cache"))]
- fn on_guild_role_update(&self, Context, GuildId, Role) {}
- fn on_guild_unavailable(&self, Context, GuildId) {}
+ fn on_guild_role_update(&self, _: Context, _: GuildId, _: Role) {}
+ fn on_guild_unavailable(&self, _: Context, _: GuildId) {}
#[cfg(feature="cache")]
- fn on_guild_update(&self, Context, Option<Arc<RwLock<Guild>>>, PartialGuild) {}
+ fn on_guild_update(&self, _: Context, _: Option<Arc<RwLock<Guild>>>, _: PartialGuild) {}
#[cfg(not(feature="cache"))]
- fn on_guild_update(&self, Context, PartialGuild) {}
- fn on_message(&self, Context, Message) {}
- fn on_message_delete(&self, Context, ChannelId, MessageId) {}
- fn on_message_delete_bulk(&self, Context, ChannelId, Vec<MessageId>) {}
- fn on_reaction_add(&self, Context, Reaction) {}
- fn on_reaction_remove(&self, Context, Reaction) {}
- fn on_reaction_remove_all(&self, Context, ChannelId, MessageId) {}
- fn on_message_update(&self, Context, MessageUpdateEvent) {}
- fn on_presence_replace(&self, Context, Vec<Presence>) {}
- fn on_presence_update(&self, Context, PresenceUpdateEvent) {}
- fn on_ready(&self, Context, Ready) {}
- fn on_resume(&self, Context, ResumedEvent) {}
- fn on_typing_start(&self, Context, TypingStartEvent) {}
- fn on_unknown(&self, Context, String, Value) {}
+ fn on_guild_update(&self, _: Context, _: PartialGuild) {}
+ fn on_message(&self, _: Context, _: Message) {}
+ fn on_message_delete(&self, _: Context, _: ChannelId, _: MessageId) {}
+ fn on_message_delete_bulk(&self, _: Context, _: ChannelId, _: Vec<MessageId>) {}
+ fn on_reaction_add(&self, _: Context, _: Reaction) {}
+ fn on_reaction_remove(&self, _: Context, _: Reaction) {}
+ fn on_reaction_remove_all(&self, _: Context, _: ChannelId, _: MessageId) {}
+ fn on_message_update(&self, _: Context, _: MessageUpdateEvent) {}
+ fn on_presence_replace(&self, _: Context, _: Vec<Presence>) {}
+ fn on_presence_update(&self, _: Context, _: PresenceUpdateEvent) {}
+ fn on_ready(&self, _: Context, _: Ready) {}
+ fn on_resume(&self, _: Context, _: ResumedEvent) {}
+ fn on_typing_start(&self, _: Context, _: TypingStartEvent) {}
+ fn on_unknown(&self, _: Context, _: String, _: Value) {}
#[cfg(feature="cache")]
- fn on_user_update(&self, Context, CurrentUser, CurrentUser) {}
+ fn on_user_update(&self, _: Context, _: CurrentUser, _: CurrentUser) {}
#[cfg(not(feature="cache"))]
- fn on_user_update(&self, Context, CurrentUser) {}
- fn on_voice_server_update(&self, Context, VoiceServerUpdateEvent) {}
- fn on_voice_state_update(&self, Context, Option<GuildId>, VoiceState) {}
- fn on_webhook_update(&self, Context, GuildId, ChannelId) {}
+ fn on_user_update(&self, _: Context, _: CurrentUser) {}
+ fn on_voice_server_update(&self, _: Context, _: VoiceServerUpdateEvent) {}
+ fn on_voice_state_update(&self, _: Context, _: Option<GuildId>, _: VoiceState) {}
+ fn on_webhook_update(&self, _: Context, _: GuildId, _: ChannelId) {}
}
diff --git a/src/client/event_store.rs b/src/client/event_store.rs
deleted file mode 100644
index 6732225..0000000
--- a/src/client/event_store.rs
+++ /dev/null
@@ -1,95 +0,0 @@
-use serde_json::Value;
-use std::collections::HashMap;
-use std::sync::Arc;
-use super::context::Context;
-use ::model::event::*;
-use ::model::*;
-
-#[cfg(feature="cache")]
-use std::sync::RwLock;
-
-// This should use type macros when stable receives the type macro
-// stabilization patch.
-//
-// This implementation should be:
-//
-// ```rust,ignore
-// macro_rules! efn {
-// ($def:ty) => {
-// Option<Arc<Box<$def> + Send + Sync + 'static>>
-// }
-// }
-// ```
-//
-// Where each field will look like:
-//
-// ```rust,ignore
-// pub something: efn!(Fn(Context, ...)),
-// ```
-#[allow(type_complexity)]
-#[derive(Default)]
-pub struct EventStore {
- pub on_cached: Option<Arc<Fn(Context, Vec<GuildId>) + 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>>,
- 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")]
- 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_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")]
- pub on_guild_delete: Option<Arc<Fn(Context, PartialGuild, Option<Arc<RwLock<Guild>>>) + Send + Sync + 'static>>,
- #[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")]
- pub on_guild_member_removal: Option<Arc<Fn(Context, GuildId, User, Option<Member>) + Send + Sync + 'static>>,
- #[cfg(not(feature="cache"))]
- pub on_guild_member_removal: Option<Arc<Fn(Context, GuildId, User) + Send + Sync + 'static>>,
- #[cfg(feature="cache")]
- pub on_guild_member_update: Option<Arc<Fn(Context, Option<Member>, Member) + Send + Sync + 'static>>,
- #[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")]
- pub on_guild_role_delete: Option<Arc<Fn(Context, GuildId, RoleId, Option<Role>) + Send + Sync + 'static>>,
- #[cfg(not(feature="cache"))]
- pub on_guild_role_delete: Option<Arc<Fn(Context, GuildId, RoleId) + Send + Sync + 'static>>,
- #[cfg(feature="cache")]
- pub on_guild_role_update: Option<Arc<Fn(Context, GuildId, Option<Role>, Role) + Send + Sync + 'static>>,
- #[cfg(not(feature="cache"))]
- pub on_guild_role_update: Option<Arc<Fn(Context, GuildId, Role) + Send + Sync + 'static>>,
- pub on_guild_unavailable: Option<Arc<Fn(Context, GuildId) + Send + Sync + 'static>>,
- #[cfg(feature="cache")]
- pub on_guild_update: Option<Arc<Fn(Context, Option<Arc<RwLock<Guild>>>, PartialGuild) + Send + Sync + 'static>>,
- #[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_delete: Option<Arc<Fn(Context, ChannelId, MessageId) + Send + Sync + 'static>>,
- pub on_message_delete_bulk: Option<Arc<Fn(Context, ChannelId, Vec<MessageId>) + Send + Sync + 'static>>,
- pub on_reaction_add: Option<Arc<Fn(Context, Reaction) + Send + Sync + 'static>>,
- 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>>,
- 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_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, Value) + 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>>,
- 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/mod.rs b/src/client/mod.rs
index 6672341..5f47b1f 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -145,9 +145,9 @@ pub struct Client<H: EventHandler + Send + Sync + 'static> {
///
/// impl EventHandler for Handler {
/// fn on_message(&self, ctx: Context, _: Message) { reg!(ctx "MessageCreate") }
- /// fn on_message_delete(&self, ctx: Context, _: Message) { reg!(ctx "MessageDelete") }
- /// fn on_message_delete_bulk(&self, ctx: Context, _: Vec<Message>) { reg!(ctx "MessageDeleteBulk") }
- /// fn on_message_update(&self, ctx: Context, _: Message) { reg!(ctx "MessageUpdate") }
+ /// fn on_message_delete(&self, ctx: Context, _: ChannelId, _: MessageId) { reg!(ctx "MessageDelete") }
+ /// fn on_message_delete_bulk(&self, ctx: Context, _: ChannelId, _: Vec<MessageId>) { reg!(ctx "MessageDeleteBulk") }
+ /// fn on_message_update(&self, ctx: Context, _: ChannelId, _: MessageId) { reg!(ctx "MessageUpdate") }
/// }
///
/// let mut client = Client::new(&env::var("DISCORD_TOKEN").unwrap(), Handler);