diff options
| author | Austin Hellyer <[email protected]> | 2016-11-05 14:44:11 -0700 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-05 14:44:11 -0700 |
| commit | e3416d3f511894553b7625c501043077977ccb4d (patch) | |
| tree | c2f9f5d35a90c649dcc67c6d15e4a9ae8478cdeb /src/client/dispatch.rs | |
| parent | Update URLs to GitLab (diff) | |
| download | serenity-e3416d3f511894553b7625c501043077977ccb4d.tar.xz serenity-e3416d3f511894553b7625c501043077977ccb4d.zip | |
Add message reactions
Add message reaction structs and an enum to differentiate between the
two types of reactions, as well as event decoding and event handlers
with dispatches.
The following is, more or less, what is added:
- `reactions` field to the `Message` struct;
- `MessageReaction` struct, which is a consolidated form of reaction,
containing the type of reaction, the number of them, and whether the
current user has performed that type of reaction;
- `Reaction`, a struct containing the information about a reaction
- `ReactionType`, an enum to differentiate between the two types of
reactions: `Custom` (a guild's custom emoji) and `Unicode` (twemoji);
- Decoding for `MESSAGE_REACTION_ADD` and `MESSAGE_REACTION_REMOVE`;
- Permission flag `ADD_REACTIONS`;
- `Message::react` method;
- Three `http` payload senders: `create_reaction`, `delete_reaction`,
and `get_reaction_users`;
- Three `Context` methods of equal names to the above.
Diffstat (limited to 'src/client/dispatch.rs')
| -rw-r--r-- | src/client/dispatch.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 5e206ee..567bc6e 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -488,6 +488,30 @@ pub fn dispatch(event: Result<Event>, }); } }, + Ok(Event::ReactionAdd(event)) => { + if let Some(ref handler) = handler!(on_reaction_add, event_store) { + let context = context(Some(event.reaction.channel_id), + conn, + login_type); + let handler = handler.clone(); + + thread::spawn(move || { + (handler)(context, event.reaction); + }); + } + }, + Ok(Event::ReactionRemove(event)) => { + if let Some(ref handler) = handler!(on_reaction_remove, event_store) { + let context = context(Some(event.reaction.channel_id), + conn, + login_type); + let handler = handler.clone(); + + thread::spawn(move || { + (handler)(context, event.reaction); + }); + } + }, Ok(Event::Ready(event)) => { if let Some(ref handler) = handler!(on_ready, event_store) { update!(update_with_ready, event); |