Skip to content

Commit d95db29

Browse files
authored
feat: add new poll system message type (#1213)
Signed-off-by: Snipy7374 <[email protected]>
1 parent ac5a936 commit d95db29

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

changelog/1212.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add new :attr:`~MessageType.poll_result` message type.

disnake/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class MessageType(Enum):
263263
guild_incident_alert_mode_disabled = 37
264264
guild_incident_report_raid = 38
265265
guild_incident_report_false_alarm = 39
266+
poll_result = 46
266267

267268

268269
class PartyType(Enum):

disnake/message.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,35 @@ def system_content(self) -> Optional[str]:
15881588
if self.type is MessageType.guild_incident_report_false_alarm:
15891589
return f"{self.author.name} resolved an Activity Alert."
15901590

1591+
if self.type is MessageType.poll_result:
1592+
if not self.embeds:
1593+
return
1594+
1595+
poll_result_embed = self.embeds[0]
1596+
poll_embed_fields: Dict[str, str] = {}
1597+
if not poll_result_embed._fields:
1598+
return
1599+
1600+
for field in poll_result_embed._fields:
1601+
poll_embed_fields[field["name"]] = field["value"]
1602+
1603+
# should never be none
1604+
question = poll_embed_fields["poll_question_text"]
1605+
# should never be none
1606+
total_votes = poll_embed_fields["total_votes"]
1607+
winning_answer = poll_embed_fields.get("victor_answer_text")
1608+
winning_answer_votes = poll_embed_fields.get("victor_answer_votes")
1609+
msg = f"{self.author.display_name}'s poll {question} has closed."
1610+
1611+
if winning_answer and winning_answer_votes:
1612+
msg += (
1613+
f"\n\n{winning_answer}"
1614+
f"\nWinning answer • {(100 * int(winning_answer_votes)) // int(total_votes)}%"
1615+
)
1616+
else:
1617+
msg += "\n\nThere was no winner."
1618+
return msg
1619+
15911620
# in the event of an unknown or unsupported message type, we return nothing
15921621
return None
15931622

disnake/types/embed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EmbedAuthor(TypedDict):
5050
proxy_icon_url: NotRequired[str]
5151

5252

53-
EmbedType = Literal["rich", "image", "video", "gifv", "article", "link"]
53+
EmbedType = Literal["rich", "image", "video", "gifv", "article", "link", "poll_result"]
5454

5555

5656
class Embed(TypedDict, total=False):

disnake/types/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class RoleSubscriptionData(TypedDict):
8080

8181

8282
# fmt: off
83-
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]
83+
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]
8484
# fmt: on
8585

8686

docs/api/messages.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,12 @@ MessageType
401401

402402
.. versionadded:: 2.10
403403

404+
.. attribute:: poll_result
405+
406+
The system message denoting that a poll expired, announcing the most voted answer.
407+
408+
.. versionadded:: 2.10
409+
404410
PollLayoutType
405411
~~~~~~~~~~~~~~
406412

@@ -414,6 +420,7 @@ PollLayoutType
414420

415421
The default poll layout type.
416422

423+
417424
Events
418425
------
419426

0 commit comments

Comments
 (0)