mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-13 05:15:22 +00:00
Add support for burst reactions
This commit is contained in:
parent
5126323640
commit
97ae6409b0
@ -30,6 +30,7 @@ from typing import TYPE_CHECKING, Literal, Optional, Set, List, Tuple, Union
|
|||||||
from .enums import ChannelType, try_enum
|
from .enums import ChannelType, try_enum
|
||||||
from .utils import _get_as_snowflake
|
from .utils import _get_as_snowflake
|
||||||
from .app_commands import AppCommandPermissions
|
from .app_commands import AppCommandPermissions
|
||||||
|
from .colour import Colour
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .types.gateway import (
|
from .types.gateway import (
|
||||||
@ -207,9 +208,29 @@ class RawReactionActionEvent(_RawReprMixin):
|
|||||||
``REACTION_REMOVE`` for reaction removal.
|
``REACTION_REMOVE`` for reaction removal.
|
||||||
|
|
||||||
.. versionadded:: 1.3
|
.. 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:
|
def __init__(self, data: ReactionActionEvent, emoji: PartialEmoji, event_type: ReactionActionType) -> None:
|
||||||
self.message_id: int = int(data['message_id'])
|
self.message_id: int = int(data['message_id'])
|
||||||
@ -219,12 +240,22 @@ class RawReactionActionEvent(_RawReprMixin):
|
|||||||
self.event_type: ReactionActionType = event_type
|
self.event_type: ReactionActionType = event_type
|
||||||
self.member: Optional[Member] = None
|
self.member: Optional[Member] = None
|
||||||
self.message_author_id: Optional[int] = _get_as_snowflake(data, 'message_author_id')
|
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:
|
try:
|
||||||
self.guild_id: Optional[int] = int(data['guild_id'])
|
self.guild_id: Optional[int] = int(data['guild_id'])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.guild_id: Optional[int] = None
|
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):
|
class RawReactionClearEvent(_RawReprMixin):
|
||||||
"""Represents the payload for a :func:`on_raw_reaction_clear` event.
|
"""Represents the payload for a :func:`on_raw_reaction_clear` event.
|
||||||
|
@ -74,20 +74,40 @@ class Reaction:
|
|||||||
emoji: Union[:class:`Emoji`, :class:`PartialEmoji`, :class:`str`]
|
emoji: Union[:class:`Emoji`, :class:`PartialEmoji`, :class:`str`]
|
||||||
The reaction emoji. May be a custom emoji, or a unicode emoji.
|
The reaction emoji. May be a custom emoji, or a unicode emoji.
|
||||||
count: :class:`int`
|
count: :class:`int`
|
||||||
Number of times this reaction was made
|
Number of times this reaction was made. This is a sum of :attr:`normal_count` and :attr:`burst_count`.
|
||||||
me: :class:`bool`
|
me: :class:`bool`
|
||||||
If the user sent this reaction.
|
If the user sent this reaction.
|
||||||
message: :class:`Message`
|
message: :class:`Message`
|
||||||
Message this reaction is for.
|
Message this reaction is for.
|
||||||
|
me_burst: :class:`bool`
|
||||||
|
If the user sent this super reaction.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
|
normal_count: :class:`int`
|
||||||
|
The number of times this reaction was made using normal reactions.
|
||||||
|
This is not available in the gateway events such as :func:`on_reaction_add`
|
||||||
|
or :func:`on_reaction_remove`.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
|
burst_count: :class:`int`
|
||||||
|
The number of times this reaction was made using super reactions.
|
||||||
|
This is not available in the gateway events such as :func:`on_reaction_add`
|
||||||
|
or :func:`on_reaction_remove`.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ('message', 'count', 'emoji', 'me')
|
__slots__ = ('message', 'count', 'emoji', 'me', 'me_burst', 'normal_count', 'burst_count')
|
||||||
|
|
||||||
def __init__(self, *, message: Message, data: ReactionPayload, emoji: Optional[Union[PartialEmoji, Emoji, str]] = None):
|
def __init__(self, *, message: Message, data: ReactionPayload, emoji: Optional[Union[PartialEmoji, Emoji, str]] = None):
|
||||||
self.message: Message = message
|
self.message: Message = message
|
||||||
self.emoji: Union[PartialEmoji, Emoji, str] = emoji or message._state.get_reaction_emoji(data['emoji'])
|
self.emoji: Union[PartialEmoji, Emoji, str] = emoji or message._state.get_reaction_emoji(data['emoji'])
|
||||||
self.count: int = data.get('count', 1)
|
self.count: int = data.get('count', 1)
|
||||||
self.me: bool = data['me']
|
self.me: bool = data['me']
|
||||||
|
details = data.get('count_details', {})
|
||||||
|
self.normal_count: int = details.get('normal', 0)
|
||||||
|
self.burst_count: int = details.get('burst', 0)
|
||||||
|
self.me_burst: bool = data.get('me_burst', False)
|
||||||
|
|
||||||
def is_custom_emoji(self) -> bool:
|
def is_custom_emoji(self) -> bool:
|
||||||
""":class:`bool`: If this is a custom emoji."""
|
""":class:`bool`: If this is a custom emoji."""
|
||||||
|
@ -101,6 +101,8 @@ class MessageReactionAddEvent(TypedDict):
|
|||||||
member: NotRequired[MemberWithUser]
|
member: NotRequired[MemberWithUser]
|
||||||
guild_id: NotRequired[Snowflake]
|
guild_id: NotRequired[Snowflake]
|
||||||
message_author_id: NotRequired[Snowflake]
|
message_author_id: NotRequired[Snowflake]
|
||||||
|
burst: bool
|
||||||
|
burst_colors: NotRequired[List[str]]
|
||||||
|
|
||||||
|
|
||||||
class MessageReactionRemoveEvent(TypedDict):
|
class MessageReactionRemoveEvent(TypedDict):
|
||||||
@ -109,6 +111,7 @@ class MessageReactionRemoveEvent(TypedDict):
|
|||||||
message_id: Snowflake
|
message_id: Snowflake
|
||||||
emoji: PartialEmoji
|
emoji: PartialEmoji
|
||||||
guild_id: NotRequired[Snowflake]
|
guild_id: NotRequired[Snowflake]
|
||||||
|
burst: bool
|
||||||
|
|
||||||
|
|
||||||
class MessageReactionRemoveAllEvent(TypedDict):
|
class MessageReactionRemoveAllEvent(TypedDict):
|
||||||
|
@ -50,10 +50,18 @@ class ChannelMention(TypedDict):
|
|||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
|
||||||
|
class ReactionCountDetails(TypedDict):
|
||||||
|
burst: int
|
||||||
|
normal: int
|
||||||
|
|
||||||
|
|
||||||
class Reaction(TypedDict):
|
class Reaction(TypedDict):
|
||||||
count: int
|
count: int
|
||||||
me: bool
|
me: bool
|
||||||
emoji: PartialEmoji
|
emoji: PartialEmoji
|
||||||
|
me_burst: bool
|
||||||
|
count_details: ReactionCountDetails
|
||||||
|
burst_colors: List[str]
|
||||||
|
|
||||||
|
|
||||||
class Attachment(TypedDict):
|
class Attachment(TypedDict):
|
||||||
|
12
docs/api.rst
12
docs/api.rst
@ -1029,6 +1029,12 @@ Reactions
|
|||||||
Consider using :func:`on_raw_reaction_add` if you need this and do not otherwise want
|
Consider using :func:`on_raw_reaction_add` if you need this and do not otherwise want
|
||||||
to enable the members intent.
|
to enable the members intent.
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
This event does not have a way of differentiating whether a reaction is a
|
||||||
|
burst reaction (also known as "super reaction") or not. If you need this,
|
||||||
|
consider using :func:`on_raw_reaction_add` instead.
|
||||||
|
|
||||||
:param reaction: The current state of the reaction.
|
:param reaction: The current state of the reaction.
|
||||||
:type reaction: :class:`Reaction`
|
:type reaction: :class:`Reaction`
|
||||||
:param user: The user who added the reaction.
|
:param user: The user who added the reaction.
|
||||||
@ -1051,6 +1057,12 @@ Reactions
|
|||||||
Consider using :func:`on_raw_reaction_remove` if you need this and do not want
|
Consider using :func:`on_raw_reaction_remove` if you need this and do not want
|
||||||
to enable the members intent.
|
to enable the members intent.
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
This event does not have a way of differentiating whether a reaction is a
|
||||||
|
burst reaction (also known as "super reaction") or not. If you need this,
|
||||||
|
consider using :func:`on_raw_reaction_remove` instead.
|
||||||
|
|
||||||
:param reaction: The current state of the reaction.
|
:param reaction: The current state of the reaction.
|
||||||
:type reaction: :class:`Reaction`
|
:type reaction: :class:`Reaction`
|
||||||
:param user: The user whose reaction was removed.
|
:param user: The user whose reaction was removed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user