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/model/gateway.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/model/gateway.rs')
| -rw-r--r-- | src/model/gateway.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/model/gateway.rs b/src/model/gateway.rs index b267164..cf226df 100644 --- a/src/model/gateway.rs +++ b/src/model/gateway.rs @@ -212,6 +212,16 @@ pub struct PresencesReplaceEvent { pub presences: Vec<Presence>, } +#[derive(Clone, Debug)] +pub struct ReactionAddEvent { + pub reaction: Reaction, +} + +#[derive(Clone, Debug)] +pub struct ReactionRemoveEvent { + pub reaction: Reaction, +} + /// The "Ready" event, containing initial state #[derive(Clone, Debug)] pub struct ReadyEvent { @@ -439,6 +449,18 @@ pub enum Event { PresenceUpdate(PresenceUpdateEvent), /// The precense list of the user's friends should be replaced entirely PresencesReplace(PresencesReplaceEvent), + /// A reaction was added to a message. + /// + /// Fires the [`on_message_reaction_add`] event handler. + /// + /// [`on_message_reaction_add`]: ../client/struct.Client.html#method.on_message_reaction_add + ReactionAdd(ReactionAddEvent), + /// A reaction was removed to a message. + /// + /// Fires the [`on_message_reaction_remove`] event handler. + /// + /// [`on_message_reaction_remove`]: ../client/struct.Client.html#method.on_message_reaction_remove + ReactionRemove(ReactionRemoveEvent), /// The first event in a connection, containing the initial state. /// /// May also be received at a later time in the event of a reconnect. @@ -629,6 +651,14 @@ impl Event { channel_id: try!(remove(&mut value, "channel_id").and_then(ChannelId::decode)), ids: try!(decode_array(try!(remove(&mut value, "ids")), MessageId::decode)), })) + } else if kind == "MESSAGE_REACTION_ADD" { + Ok(Event::ReactionAdd(ReactionAddEvent { + reaction: try!(Reaction::decode(Value::Object(value))) + })) + } else if kind == "MESSAG_REACTION_REMOVE" { + Ok(Event::ReactionRemove(ReactionRemoveEvent { + reaction: try!(Reaction::decode(Value::Object(value))) + })) } else if kind == "MESSAGE_UPDATE" { missing!(value, Event::MessageUpdate(MessageUpdateEvent { id: try!(remove(&mut value, "id").and_then(MessageId::decode)), |