diff --git a/changelog/1212.feature.rst b/changelog/1212.feature.rst new file mode 100644 index 0000000000..87babbf215 --- /dev/null +++ b/changelog/1212.feature.rst @@ -0,0 +1 @@ +Add new :attr:`~MessageType.poll_result` message type. diff --git a/disnake/enums.py b/disnake/enums.py index 8c587ca902..1cf075c85f 100644 --- a/disnake/enums.py +++ b/disnake/enums.py @@ -263,6 +263,7 @@ class MessageType(Enum): guild_incident_alert_mode_disabled = 37 guild_incident_report_raid = 38 guild_incident_report_false_alarm = 39 + poll_result = 46 class PartyType(Enum): diff --git a/disnake/message.py b/disnake/message.py index f67da56a28..fc9c93539c 100644 --- a/disnake/message.py +++ b/disnake/message.py @@ -1588,6 +1588,35 @@ def system_content(self) -> Optional[str]: if self.type is MessageType.guild_incident_report_false_alarm: return f"{self.author.name} resolved an Activity Alert." + if self.type is MessageType.poll_result: + if not self.embeds: + return + + poll_result_embed = self.embeds[0] + poll_embed_fields: Dict[str, str] = {} + if not poll_result_embed._fields: + return + + for field in poll_result_embed._fields: + poll_embed_fields[field["name"]] = field["value"] + + # should never be none + question = poll_embed_fields["poll_question_text"] + # should never be none + total_votes = poll_embed_fields["total_votes"] + winning_answer = poll_embed_fields.get("victor_answer_text") + winning_answer_votes = poll_embed_fields.get("victor_answer_votes") + msg = f"{self.author.display_name}'s poll {question} has closed." + + if winning_answer and winning_answer_votes: + msg += ( + f"\n\n{winning_answer}" + f"\nWinning answer • {(100 * int(winning_answer_votes)) // int(total_votes)}%" + ) + else: + msg += "\n\nThere was no winner." + return msg + # in the event of an unknown or unsupported message type, we return nothing return None diff --git a/disnake/types/embed.py b/disnake/types/embed.py index 47e6afa59f..a066b084d3 100644 --- a/disnake/types/embed.py +++ b/disnake/types/embed.py @@ -50,7 +50,7 @@ class EmbedAuthor(TypedDict): proxy_icon_url: NotRequired[str] -EmbedType = Literal["rich", "image", "video", "gifv", "article", "link"] +EmbedType = Literal["rich", "image", "video", "gifv", "article", "link", "poll_result"] class Embed(TypedDict, total=False): diff --git a/disnake/types/message.py b/disnake/types/message.py index 8d8431864e..1859985460 100644 --- a/disnake/types/message.py +++ b/disnake/types/message.py @@ -80,7 +80,7 @@ class RoleSubscriptionData(TypedDict): # fmt: off -MessageType = Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 36, 37, 38, 39] +MessageType = Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 36, 37, 38, 39, 46] # fmt: on diff --git a/docs/api/messages.rst b/docs/api/messages.rst index 6c02bc0208..89f92f52f7 100644 --- a/docs/api/messages.rst +++ b/docs/api/messages.rst @@ -401,6 +401,12 @@ MessageType .. versionadded:: 2.10 + .. attribute:: poll_result + + The system message denoting that a poll expired, announcing the most voted answer. + + .. versionadded:: 2.10 + PollLayoutType ~~~~~~~~~~~~~~ @@ -414,6 +420,7 @@ PollLayoutType The default poll layout type. + Events ------