From 5784ea6eefe41319e295ca0184605354a2af5d55 Mon Sep 17 00:00:00 2001 From: Filip Hoffmann Date: Wed, 22 Jul 2026 00:36:42 +0200 Subject: [PATCH] more reaction endpoints --- src/grom.gleam | 135 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/src/grom.gleam b/src/grom.gleam index 18b3c59..28be632 100644 --- a/src/grom.gleam +++ b/src/grom.gleam @@ -22,7 +22,7 @@ import multipart_form import multipart_form/field import status_code -const version: String = "v6.0.0" +const version: String = "v7.0.0" /// A snowflake is another name for an ID. /// @@ -15663,3 +15663,136 @@ pub fn delete_message_reaction_response( ) -> Result(Nil, RestError) { handle_no_content_response(response) } + +pub type GetReactingUsersOptions { + GetReactingUsersOptions( + get_burst_reactions: Bool, + after: Option(Snowflake(User)), + limit: Int, + ) +} + +fn get_reacting_users_options_to_query( + options: GetReactingUsersOptions, +) -> List(#(String, String)) { + [ + Ok( + #("type", case options.get_burst_reactions { + True -> "1" + False -> "0" + }), + ), + optional_to_string(options.after, "after", snowflake_to_string), + Ok(#("limit", int.to_string(options.limit))), + ] + |> list.filter_map(function.identity) +} + +/// Defaults: +/// - only normal reactions +/// - limit: 25 +pub fn new_get_reacting_users_options() -> GetReactingUsersOptions { + GetReactingUsersOptions(False, None, 25) +} + +/// Will ONLY return burst reacting users. +pub fn get_burst_reacting_users( + options: GetReactingUsersOptions, +) -> GetReactingUsersOptions { + GetReactingUsersOptions(..options, get_burst_reactions: True) +} + +pub fn get_reacting_users_after( + options: GetReactingUsersOptions, + id id: Snowflake(User), +) -> GetReactingUsersOptions { + GetReactingUsersOptions(..options, after: Some(id)) +} + +/// Limit must be between 1 and 100. +pub fn get_reacting_users_with_limit( + options: GetReactingUsersOptions, + limit: Int, +) -> GetReactingUsersOptions { + GetReactingUsersOptions(..options, limit:) +} + +pub fn get_reacting_users_request( + token token: Token, + in_channel_with_id channel_id: Snowflake(Channel), + from_message_with_id message_id: Snowflake(Message), + emoji emoji: MessageReactionEmoji, + using options: GetReactingUsersOptions, +) -> Request(String) { + let query = options |> get_reacting_users_options_to_query + + new_request( + token:, + to: "/channels/" + <> snowflake_to_string(channel_id) + <> "/messages/" + <> snowflake_to_string(message_id) + <> "/reactions/" + <> message_reaction_emoji_to_path(emoji), + method: http.Get, + ) + |> request.set_query(query) +} + +pub fn get_reacting_users_response( + response: Response(String), +) -> Result(List(User), RestError) { + handle_response(response, decode_with: decode.list(of: user_decoder())) +} + +/// Removes all reactions from a message. +/// +/// Requires the `AllowManagingMessages` permission. +pub fn delete_message_reactions_request( + token token: Token, + in_channel_with_id channel_id: Snowflake(Channel), + message_with_id message_id: Snowflake(Message), +) -> Request(String) { + new_request( + token:, + to: "/channels/" + <> snowflake_to_string(channel_id) + <> "/messages/" + <> snowflake_to_string(message_id) + <> "/reactions", + method: http.Delete, + ) +} + +pub fn delete_message_reactions_response( + response: Response(String), +) -> Result(Nil, RestError) { + handle_no_content_response(response) +} + +/// Deletes all the reactions for a given messages from a message. +/// +/// Requires the `AllowManagingMessages` permission. +pub fn delete_message_emoji_reactions_request( + token token: Token, + in_channel_with_id channel_id: Snowflake(Channel), + from_message_with_id message_id: Snowflake(Message), + emoji emoji: MessageReactionEmoji, +) -> Request(String) { + new_request( + token:, + to: "/channels/" + <> snowflake_to_string(channel_id) + <> "/messages/" + <> snowflake_to_string(message_id) + <> "/reactions/" + <> message_reaction_emoji_to_path(emoji), + method: http.Delete, + ) +} + +pub fn delete_message_emoji_reactions_response( + response: Response(String), +) -> Result(Nil, RestError) { + handle_no_content_response(response) +} -- 2.51.2