aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-18 11:53:46 -0800
committerAustin Hellyer <[email protected]>2016-11-18 11:53:46 -0800
commit0bacf7b64960ae743c6cd7407b0665781b201766 (patch)
treeff271a3e96c5ba61e2ab01ed49ac0be290961945 /src
parentA bit of docs (diff)
downloadserenity-0bacf7b64960ae743c6cd7407b0665781b201766.tar.xz
serenity-0bacf7b64960ae743c6cd7407b0665781b201766.zip
Register friend suggestion events
Diffstat (limited to 'src')
-rw-r--r--src/client/dispatch.rs20
-rw-r--r--src/client/event_store.rs2
-rw-r--r--src/client/mod.rs20
-rw-r--r--src/ext/state/mod.rs2
-rw-r--r--src/model/gateway.rs27
5 files changed, 71 insertions, 0 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs
index fa41ddc..9aff46f 100644
--- a/src/client/dispatch.rs
+++ b/src/client/dispatch.rs
@@ -265,6 +265,26 @@ fn handle_event(event: Event,
update!(update_with_channel_update, event);
}
},
+ Event::FriendSuggestionCreate(event) => {
+ if let Some(ref handler) = handler!(on_friend_suggestion_create, event_store) {
+ let context = context(None, conn, login_type);
+ let handler = handler.clone();
+
+ thread::spawn(move || {
+ (handler)(context, event.suggested_user, event.reasons);
+ });
+ }
+ },
+ Event::FriendSuggestionDelete(event) => {
+ if let Some(ref handler) = handler!(on_friend_suggestion_delete, event_store) {
+ let context = context(None, conn, login_type);
+ let handler = handler.clone();
+
+ thread::spawn(move || {
+ (handler)(context, event.suggested_user_id);
+ });
+ }
+ },
Event::GuildBanAdd(event) => {
if let Some(ref handler) = handler!(on_guild_ban_addition, event_store) {
let context = context(None, conn, login_type);
diff --git a/src/client/event_store.rs b/src/client/event_store.rs
index 98d874b..1693a73 100644
--- a/src/client/event_store.rs
+++ b/src/client/event_store.rs
@@ -38,6 +38,8 @@ pub struct EventStore {
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>>,
pub on_channel_update: Option<Arc<Fn(Context, Option<Channel>, 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, LiveGuild) + Send + Sync + 'static>>,
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 7665955..44e951b 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -520,6 +520,26 @@ impl Client {
.on_channel_update = Some(Arc::new(handler));
}
+ /// Attaches a handler for when a [`FriendSuggestionCreate`] is received.
+ ///
+ /// [`FriendSuggestionCreate`]: ../model/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.lock()
+ .unwrap()
+ .on_friend_suggestion_create = Some(Arc::new(handler));
+ }
+
+ /// Attaches a handler for when a [`FriendSuggestionDelete`] is received.
+ ///
+ /// [`FriendSuggestionDelete`]: ../model/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.lock()
+ .unwrap()
+ .on_friend_suggestion_delete = Some(Arc::new(handler));
+ }
+
/// Attaches a handler for when a [`GuildCreate`] is received.
///
/// [`GuildCreate`]: ../model/enum.Event.html#variant.GuildCreate
diff --git a/src/ext/state/mod.rs b/src/ext/state/mod.rs
index a97cc71..ce25e2a 100644
--- a/src/ext/state/mod.rs
+++ b/src/ext/state/mod.rs
@@ -258,6 +258,8 @@ impl State {
self.update_with_voice_state_update(event);
},
Event::ChannelPinsAck(_) |
+ Event::FriendSuggestionCreate(_) |
+ Event::FriendSuggestionDelete(_) |
Event::GuildBanAdd(_) |
Event::GuildBanRemove(_) |
Event::GuildIntegrationsUpdate(_) |
diff --git a/src/model/gateway.rs b/src/model/gateway.rs
index 1a286af..29dd7ce 100644
--- a/src/model/gateway.rs
+++ b/src/model/gateway.rs
@@ -63,6 +63,17 @@ pub struct ChannelUpdateEvent {
}
#[derive(Clone, Debug)]
+pub struct FriendSuggestionCreateEvent {
+ pub reasons: Vec<SuggestionReason>,
+ pub suggested_user: User,
+}
+
+#[derive(Clone, Copy, Debug)]
+pub struct FriendSuggestionDeleteEvent {
+ pub suggested_user_id: UserId,
+}
+
+#[derive(Clone, Debug)]
pub struct GuildBanAddEvent {
pub guild_id: GuildId,
pub user: User,
@@ -373,6 +384,13 @@ pub enum Event {
/// A user has been removed from a group
ChannelRecipientRemove(ChannelRecipientRemoveEvent),
ChannelUpdate(ChannelUpdateEvent),
+ /// When a suggestion for a friend is created, due to a connection like
+ /// [`Skype`].
+ ///
+ /// [`Connection::Skype`]: enum.Connection.html#variant.Skype
+ FriendSuggestionCreate(FriendSuggestionCreateEvent),
+ /// When a suggestion for a friend is removed.
+ FriendSuggestionDelete(FriendSuggestionDeleteEvent),
GuildBanAdd(GuildBanAddEvent),
GuildBanRemove(GuildBanRemoveEvent),
GuildCreate(GuildCreateEvent),
@@ -511,6 +529,15 @@ impl Event {
Ok(Event::ChannelUpdate(ChannelUpdateEvent {
channel: try!(Channel::decode(Value::Object(value))),
}))
+ } else if kind == "FRIEND_SUGGESTION_CREATE" {
+ missing!(value, Event::FriendSuggestionCreate(FriendSuggestionCreateEvent {
+ reasons: try!(decode_array(try!(remove(&mut value, "reasons")), SuggestionReason::decode)),
+ suggested_user: try!(remove(&mut value, "suggested_user").and_then(User::decode)),
+ }))
+ } else if kind == "FRIEND_SUGGESTION_DELETE" {
+ missing!(value, Event::FriendSuggestionDelete(FriendSuggestionDeleteEvent {
+ suggested_user_id: try!(remove(&mut value, "suggested_user_id").and_then(UserId::decode)),
+ }))
} else if kind == "GUILD_BAN_ADD" {
missing!(value, Event::GuildBanAdd(GuildBanAddEvent {
guild_id: try!(remove(&mut value, "guild_id").and_then(GuildId::decode)),