mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-21 10:26:47 +00:00
Add reaction type to raw events and users iterator
This commit is contained in:
parent
b5ada0a662
commit
f77ba711ba
@ -829,6 +829,11 @@ class InviteType(Enum):
|
|||||||
friend = 2
|
friend = 2
|
||||||
|
|
||||||
|
|
||||||
|
class ReactionType(Enum):
|
||||||
|
normal = 0
|
||||||
|
burst = 1
|
||||||
|
|
||||||
|
|
||||||
def create_unknown_value(cls: Type[E], val: Any) -> E:
|
def create_unknown_value(cls: Type[E], val: Any) -> E:
|
||||||
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
|
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
|
||||||
name = f'unknown_{val}'
|
name = f'unknown_{val}'
|
||||||
|
@ -941,6 +941,7 @@ class HTTPClient:
|
|||||||
emoji: str,
|
emoji: str,
|
||||||
limit: int,
|
limit: int,
|
||||||
after: Optional[Snowflake] = None,
|
after: Optional[Snowflake] = None,
|
||||||
|
type: Optional[message.ReactionType] = None,
|
||||||
) -> Response[List[user.User]]:
|
) -> Response[List[user.User]]:
|
||||||
r = Route(
|
r = Route(
|
||||||
'GET',
|
'GET',
|
||||||
@ -955,6 +956,10 @@ class HTTPClient:
|
|||||||
}
|
}
|
||||||
if after:
|
if after:
|
||||||
params['after'] = after
|
params['after'] = after
|
||||||
|
|
||||||
|
if type is not None:
|
||||||
|
params['type'] = type
|
||||||
|
|
||||||
return self.request(r, params=params)
|
return self.request(r, params=params)
|
||||||
|
|
||||||
def clear_reactions(self, channel_id: Snowflake, message_id: Snowflake) -> Response[None]:
|
def clear_reactions(self, channel_id: Snowflake, message_id: Snowflake) -> Response[None]:
|
||||||
|
@ -27,7 +27,7 @@ from __future__ import annotations
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import TYPE_CHECKING, Literal, Optional, Set, List, Tuple, Union
|
from typing import TYPE_CHECKING, Literal, Optional, Set, List, Tuple, Union
|
||||||
|
|
||||||
from .enums import ChannelType, try_enum
|
from .enums import ChannelType, try_enum, ReactionType
|
||||||
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
|
from .colour import Colour
|
||||||
@ -221,6 +221,10 @@ class RawReactionActionEvent(_RawReprMixin):
|
|||||||
and if ``event_type`` is ``REACTION_ADD``.
|
and if ``event_type`` is ``REACTION_ADD``.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
type: :class:`ReactionType`
|
||||||
|
The type of the reaction.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
@ -234,6 +238,7 @@ class RawReactionActionEvent(_RawReprMixin):
|
|||||||
'message_author_id',
|
'message_author_id',
|
||||||
'burst',
|
'burst',
|
||||||
'burst_colours',
|
'burst_colours',
|
||||||
|
'type',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, data: ReactionActionEvent, emoji: PartialEmoji, event_type: ReactionActionType) -> None:
|
def __init__(self, data: ReactionActionEvent, emoji: PartialEmoji, event_type: ReactionActionType) -> None:
|
||||||
@ -246,6 +251,7 @@ class RawReactionActionEvent(_RawReprMixin):
|
|||||||
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: bool = data.get('burst', False)
|
||||||
self.burst_colours: List[Colour] = [Colour.from_str(c) for c in data.get('burst_colours', [])]
|
self.burst_colours: List[Colour] = [Colour.from_str(c) for c in data.get('burst_colours', [])]
|
||||||
|
self.type: ReactionType = try_enum(ReactionType, data['type'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.guild_id: Optional[int] = int(data['guild_id'])
|
self.guild_id: Optional[int] = int(data['guild_id'])
|
||||||
|
@ -27,6 +27,7 @@ from typing import TYPE_CHECKING, AsyncIterator, Union, Optional
|
|||||||
|
|
||||||
from .user import User
|
from .user import User
|
||||||
from .object import Object
|
from .object import Object
|
||||||
|
from .enums import ReactionType
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -185,7 +186,7 @@ class Reaction:
|
|||||||
await self.message.clear_reaction(self.emoji)
|
await self.message.clear_reaction(self.emoji)
|
||||||
|
|
||||||
async def users(
|
async def users(
|
||||||
self, *, limit: Optional[int] = None, after: Optional[Snowflake] = None
|
self, *, limit: Optional[int] = None, after: Optional[Snowflake] = None, type: Optional[ReactionType] = None
|
||||||
) -> AsyncIterator[Union[Member, User]]:
|
) -> AsyncIterator[Union[Member, User]]:
|
||||||
"""Returns an :term:`asynchronous iterator` representing the users that have reacted to the message.
|
"""Returns an :term:`asynchronous iterator` representing the users that have reacted to the message.
|
||||||
|
|
||||||
@ -220,6 +221,11 @@ class Reaction:
|
|||||||
reacted to the message.
|
reacted to the message.
|
||||||
after: Optional[:class:`abc.Snowflake`]
|
after: Optional[:class:`abc.Snowflake`]
|
||||||
For pagination, reactions are sorted by member.
|
For pagination, reactions are sorted by member.
|
||||||
|
type: Optional[:class:`ReactionType`]
|
||||||
|
The type of reaction to return users from.
|
||||||
|
If not provided, Discord only returns users of reactions with type ``normal``.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
--------
|
--------
|
||||||
@ -251,7 +257,14 @@ class Reaction:
|
|||||||
state = message._state
|
state = message._state
|
||||||
after_id = after.id if after else None
|
after_id = after.id if after else None
|
||||||
|
|
||||||
data = await state.http.get_reaction_users(message.channel.id, message.id, emoji, retrieve, after=after_id)
|
data = await state.http.get_reaction_users(
|
||||||
|
message.channel.id,
|
||||||
|
message.id,
|
||||||
|
emoji,
|
||||||
|
retrieve,
|
||||||
|
after=after_id,
|
||||||
|
type=type.value if type is not None else None,
|
||||||
|
)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
limit -= len(data)
|
limit -= len(data)
|
||||||
|
@ -37,7 +37,7 @@ from .invite import InviteTargetType
|
|||||||
from .emoji import Emoji, PartialEmoji
|
from .emoji import Emoji, PartialEmoji
|
||||||
from .member import MemberWithUser
|
from .member import MemberWithUser
|
||||||
from .snowflake import Snowflake
|
from .snowflake import Snowflake
|
||||||
from .message import Message
|
from .message import Message, ReactionType
|
||||||
from .sticker import GuildSticker
|
from .sticker import GuildSticker
|
||||||
from .appinfo import GatewayAppInfo, PartialAppInfo
|
from .appinfo import GatewayAppInfo, PartialAppInfo
|
||||||
from .guild import Guild, UnavailableGuild
|
from .guild import Guild, UnavailableGuild
|
||||||
@ -104,6 +104,7 @@ class MessageReactionAddEvent(TypedDict):
|
|||||||
message_author_id: NotRequired[Snowflake]
|
message_author_id: NotRequired[Snowflake]
|
||||||
burst: bool
|
burst: bool
|
||||||
burst_colors: NotRequired[List[str]]
|
burst_colors: NotRequired[List[str]]
|
||||||
|
type: ReactionType
|
||||||
|
|
||||||
|
|
||||||
class MessageReactionRemoveEvent(TypedDict):
|
class MessageReactionRemoveEvent(TypedDict):
|
||||||
@ -113,6 +114,7 @@ class MessageReactionRemoveEvent(TypedDict):
|
|||||||
emoji: PartialEmoji
|
emoji: PartialEmoji
|
||||||
guild_id: NotRequired[Snowflake]
|
guild_id: NotRequired[Snowflake]
|
||||||
burst: bool
|
burst: bool
|
||||||
|
type: ReactionType
|
||||||
|
|
||||||
|
|
||||||
class MessageReactionRemoveAllEvent(TypedDict):
|
class MessageReactionRemoveAllEvent(TypedDict):
|
||||||
|
@ -57,6 +57,9 @@ class ReactionCountDetails(TypedDict):
|
|||||||
normal: int
|
normal: int
|
||||||
|
|
||||||
|
|
||||||
|
ReactionType = Literal[0, 1]
|
||||||
|
|
||||||
|
|
||||||
class Reaction(TypedDict):
|
class Reaction(TypedDict):
|
||||||
count: int
|
count: int
|
||||||
me: bool
|
me: bool
|
||||||
|
15
docs/api.rst
15
docs/api.rst
@ -3643,6 +3643,21 @@ of :class:`enum.Enum`.
|
|||||||
The invite is a friend invite.
|
The invite is a friend invite.
|
||||||
|
|
||||||
|
|
||||||
|
.. class:: ReactionType
|
||||||
|
|
||||||
|
Represents the type of a reaction.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
|
|
||||||
|
.. attribute:: normal
|
||||||
|
|
||||||
|
A normal reaction.
|
||||||
|
|
||||||
|
.. attribute:: burst
|
||||||
|
|
||||||
|
A burst reaction, also known as a "super reaction".
|
||||||
|
|
||||||
|
|
||||||
.. _discord-api-audit-logs:
|
.. _discord-api-audit-logs:
|
||||||
|
|
||||||
Audit Log Data
|
Audit Log Data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user