Add support for burst reactions

This commit is contained in:
Rapptz
2023-09-19 00:05:55 -04:00
parent 5126323640
commit 97ae6409b0
5 changed files with 77 additions and 3 deletions

View File

@ -30,6 +30,7 @@ from typing import TYPE_CHECKING, Literal, Optional, Set, List, Tuple, Union
from .enums import ChannelType, try_enum
from .utils import _get_as_snowflake
from .app_commands import AppCommandPermissions
from .colour import Colour
if TYPE_CHECKING:
from .types.gateway import (
@ -207,9 +208,29 @@ class RawReactionActionEvent(_RawReprMixin):
``REACTION_REMOVE`` for reaction removal.
.. versionadded:: 1.3
burst: :class:`bool`
Whether the reaction was a burst reaction, also known as a "super reaction".
.. versionadded:: 2.4
burst_colours: List[:class:`Colour`]
A list of colours used for burst reaction animation. Only available if ``burst`` is ``True``
and if ``event_type`` is ``REACTION_ADD``.
.. versionadded:: 2.0
"""
__slots__ = ('message_id', 'user_id', 'channel_id', 'guild_id', 'emoji', 'event_type', 'member', 'message_author_id')
__slots__ = (
'message_id',
'user_id',
'channel_id',
'guild_id',
'emoji',
'event_type',
'member',
'message_author_id',
'burst',
'burst_colours',
)
def __init__(self, data: ReactionActionEvent, emoji: PartialEmoji, event_type: ReactionActionType) -> None:
self.message_id: int = int(data['message_id'])
@ -219,12 +240,22 @@ class RawReactionActionEvent(_RawReprMixin):
self.event_type: ReactionActionType = event_type
self.member: Optional[Member] = None
self.message_author_id: Optional[int] = _get_as_snowflake(data, 'message_author_id')
self.burst: bool = data.get('burst', False)
self.burst_colours: List[Colour] = [Colour.from_str(c) for c in data.get('burst_colours', [])]
try:
self.guild_id: Optional[int] = int(data['guild_id'])
except KeyError:
self.guild_id: Optional[int] = None
@property
def burst_colors(self) -> List[Colour]:
"""An alias of :attr:`burst_colours`.
.. versionadded:: 2.4
"""
return self.burst_colours
class RawReactionClearEvent(_RawReprMixin):
"""Represents the payload for a :func:`on_raw_reaction_clear` event.