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/mod.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/mod.rs')
| -rw-r--r-- | src/client/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs index 8e291fb..50461c8 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -685,6 +685,26 @@ impl Client { .on_presence_update = Some(Arc::new(handler)); } + /// Attached a handler for when a [`ReactionAdd`] is received. + /// + /// [`ReactionAdd`]: ../model/enum.Event.html#ReactionAdd.v + pub fn on_reaction_add<F>(&mut self, handler: F) + where F: Fn(Context, Reaction) + Send + Sync + 'static { + self.event_store.lock() + .unwrap() + .on_reaction_add = Some(Arc::new(handler)) + } + + /// Attached a handler for when a [`ReactionRemove`] is received. + /// + /// [`ReactionRemove`]: ../model/enum.Event.html#ReactionRemove.v + pub fn on_reaction_remove<F>(&mut self, handler: F) + where F: Fn(Context, Reaction) + Send + Sync + 'static { + self.event_store.lock() + .unwrap() + .on_reaction_remove = Some(Arc::new(handler)) + } + /// Register an event to be called whenever a Ready event is received. /// /// Registering a handler for the ready event is good for noting when your |