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/http.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/http.rs')
| -rw-r--r-- | src/client/http.rs | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/client/http.rs b/src/client/http.rs index 3421359..9d29ae6 100644 --- a/src/client/http.rs +++ b/src/client/http.rs @@ -116,8 +116,7 @@ pub fn create_guild(map: Value) -> Result<Guild> { Guild::decode(try!(serde_json::from_reader(response))) } -pub fn create_guild_integration( - guild_id: u64, +pub fn create_guild_integration(guild_id: u64, integration_id: u64, map: Value) -> Result<()> { let body = try!(serde_json::to_string(&map)); @@ -161,6 +160,18 @@ pub fn create_private_channel(map: Value) PrivateChannel::decode(try!(serde_json::from_reader(response))) } +pub fn create_reaction(channel_id: u64, + message_id: u64, + reaction_type: ReactionType) + -> Result<()> { + verify(204, request!(Route::ChannelsIdMessagesIdReactionsUserIdType, + put, + "/channels/{}/messages/{}/reactions/{}/@me", + channel_id, + message_id, + reaction_type.as_data())) +} + pub fn create_role(guild_id: u64) -> Result<Role> { let body = String::from("{}"); let response = request!(Route::GuildsIdRoles, @@ -236,6 +247,22 @@ pub fn delete_permission(channel_id: u64, target_id: u64) target_id)) } +pub fn delete_reaction(channel_id: u64, + message_id: u64, + user_id: Option<u64>, + reaction_type: ReactionType) + -> Result<()> { + let user = user_id.map(|uid| uid.to_string()).unwrap_or("@me".to_string()); + + verify(204, request!(Route::ChannelsIdMessagesIdReactionsUserIdType, + delete, + "/channels/{}/messages/{}/reactions/{}/{}", + channel_id, + message_id, + reaction_type.as_data(), + user)) +} + pub fn delete_role(guild_id: u64, role_id: u64) -> Result<()> { verify(204, request!(Route::GuildsIdRolesId, delete, @@ -508,6 +535,31 @@ pub fn get_pins(channel_id: u64) -> Result<Vec<Message>> { decode_array(try!(serde_json::from_reader(response)), Message::decode) } +pub fn get_reaction_users(channel_id: u64, + message_id: u64, + reaction_type: ReactionType, + limit: u8, + after: Option<u64>) + -> Result<Vec<User>> { + let mut uri = format!("/channels/{}/messages/{}/reactions/{}?limit={}", + channel_id, + message_id, + reaction_type.as_data(), + limit); + + if let Some(user_id) = after { + uri.push_str("&after="); + uri.push_str(&user_id.to_string()); + } + + let response = request!(Route::ChannelsIdMessagesIdReactionsUserIdType, + get, + "{}", + uri); + + decode_array(try!(serde_json::from_reader(response)), User::decode) +} + pub fn get_user(user_id: u64) -> Result<CurrentUser> { let response = request!(Route::UsersId, get, "/users/{}", user_id); |