From 0cb273bfb2d2cd01e36649a6a8f52b77647b040d Mon Sep 17 00:00:00 2001 From: Filip Hoffmann Date: Wed, 22 Jul 2026 02:47:49 +0200 Subject: [PATCH] poll endpoints --- src/grom.gleam | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/grom.gleam b/src/grom.gleam index d97b592..80b32b5 100644 --- a/src/grom.gleam +++ b/src/grom.gleam @@ -16234,3 +16234,96 @@ pub fn get_application_skus_response( ) -> Result(List(Sku), RestError) { handle_response(response, decode_with: decode.list(sku_decoder())) } + +pub opaque type GetPollAnswerVotersOptions { + GetPollAnswerVotersOptions(after: Option(Snowflake(User)), limit: Int) +} + +/// Default limit is 25. +pub fn new_get_poll_answer_voters_options() -> GetPollAnswerVotersOptions { + GetPollAnswerVotersOptions(None, 25) +} + +pub fn get_poll_answer_voters_after( + options: GetPollAnswerVotersOptions, + id id: Snowflake(User), +) -> GetPollAnswerVotersOptions { + GetPollAnswerVotersOptions(..options, after: Some(id)) +} + +/// Limit must be between 1 and 100. +pub fn get_poll_answer_voters_with_limit( + options: GetPollAnswerVotersOptions, + limit: Int, +) -> GetPollAnswerVotersOptions { + GetPollAnswerVotersOptions(..options, limit:) +} + +fn get_poll_answer_voters_options_to_query( + options: GetPollAnswerVotersOptions, +) -> List(#(String, String)) { + [ + optional_to_string(options.after, "after", snowflake_to_string), + Ok(#("limit", int.to_string(options.limit))), + ] + |> list.filter_map(function.identity) +} + +/// Get a list of users who voted for a specific poll answer. +pub fn get_poll_answer_voters_request( + token token: Token, + in_channel_with_id channel_id: Snowflake(Channel), + for_message_with_id message_id: Snowflake(Message), + answer_with_id answer_id: Int, + using options: GetPollAnswerVotersOptions, +) -> Request(String) { + let query = options |> get_poll_answer_voters_options_to_query + + new_request( + token:, + to: "/channels/" + <> snowflake_to_string(channel_id) + <> "/polls/" + <> snowflake_to_string(message_id) + <> "/answers/" + <> int.to_string(answer_id), + method: http.Get, + ) + |> request.set_query(query) +} + +pub fn get_poll_answer_voters_response( + response: Response(String), +) -> Result(List(User), RestError) { + handle_response( + response, + decode_with: decode.field( + "users", + decode.list(of: user_decoder()), + decode.success, + ), + ) +} + +/// You cannot end other users' polls. +pub fn end_poll_request( + token token: Token, + in_channel_with_id channel_id: Snowflake(Channel), + for_message_with_id message_id: Snowflake(Message), +) -> Request(String) { + new_request( + token:, + to: "/channels/" + <> snowflake_to_string(channel_id) + <> "/polls/" + <> snowflake_to_string(message_id) + <> "/expire", + method: http.Post, + ) +} + +pub fn end_poll_response( + response: Response(String), +) -> Result(Message, RestError) { + handle_response(response, decode_with: message_decoder()) +} -- 2.51.2