diff --git a/interactions/api/http/reaction.py b/interactions/api/http/reaction.py index 93cdeeb03..6701f621a 100644 --- a/interactions/api/http/reaction.py +++ b/interactions/api/http/reaction.py @@ -110,7 +110,12 @@ async def remove_all_reactions_of_emoji( ) async def get_reactions_of_emoji( - self, channel_id: int, message_id: int, emoji: str + self, + channel_id: int, + message_id: int, + emoji: str, + limit: int = 25, + after: int = None, ) -> List[dict]: """ Gets the users who reacted to the emoji. @@ -118,12 +123,22 @@ async def get_reactions_of_emoji( :param channel_id: Channel snowflake ID. :param message_id: Message snowflake ID. :param emoji: The emoji to get (format: `name:id`) + :param limit: Max number of users to return (1-100) + :param after: Get users after this user ID :return: A list of users who sent that emoji. """ + + params_set = { + f"after={after}" if after else None, + f"limit={limit}", + } + final = "&".join([item for item in params_set if item is not None]) + return await self._req.request( Route( "GET", - "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}", + "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}" + + f"{'?' + final if final is not None else ''}", channel_id=channel_id, message_id=message_id, emoji=emoji, diff --git a/interactions/api/http/reaction.pyi b/interactions/api/http/reaction.pyi index b54b48187..a3f3c5d62 100644 --- a/interactions/api/http/reaction.pyi +++ b/interactions/api/http/reaction.pyi @@ -18,5 +18,5 @@ class ReactionRequest: self, channel_id: int, message_id: int, emoji: str ) -> None: ... async def get_reactions_of_emoji( - self, channel_id: int, message_id: int, emoji: str + self, channel_id: int, message_id: int, emoji: str, limit: int = 25, after: int = None, ) -> List[dict]: ... diff --git a/interactions/api/models/message.py b/interactions/api/models/message.py index 641997ee7..6cf9541ae 100644 --- a/interactions/api/models/message.py +++ b/interactions/api/models/message.py @@ -20,6 +20,26 @@ from .team import Application from .user import User +__all__ = ( + "MessageType", + "Message", + "MessageReference", + "MessageActivity", + "MessageInteraction", + "ChannelMention", + "Embed", + "EmbedAuthor", + "EmbedProvider", + "EmbedImageStruct", + "EmbedField", + "Attachment", + "Emoji", + "EmbedFooter", + "ReactionObject", + "PartialSticker", + "Sticker", +) + class MessageType(IntEnum): """An enumerable object representing the types of messages.""" @@ -898,6 +918,8 @@ async def edit( :type files: Optional[Union[File, List[File]]] :param embeds?: An embed, or list of embeds for the message. :type embeds: Optional[Union[Embed, List[Embed]]] + :param suppress_embeds?: Whether to suppress embeds in the message. + :type suppress_embeds: Optional[bool] :param allowed_mentions?: The message interactions/mention limits that the message can refer to. :type allowed_mentions: Optional[MessageInteraction] :param components?: A component, or list of components for the message. If `[]` the components will be removed @@ -1214,12 +1236,56 @@ async def remove_reaction_from( if isinstance(emoji, Emoji) else emoji ) + if not self._client: + raise AttributeError("HTTPClient not found!") _user_id = user if isinstance(user, int) else user.id return await self._client.remove_user_reaction( channel_id=int(self.channel_id), message_id=int(self.id), user_id=_user_id, emoji=_emoji ) + async def get_users_from_reaction( + self, + emoji: Union[str, "Emoji"], + ) -> List[User]: + """ + Retrieves all users that reacted to the message with the given emoji + + :param emoji: The Emoji as object or formatted as `name:id` + :type emoji: Union[str, Emoji] + :return: A list of user objects + :rtype: List[User] + """ + if not self._client: + raise AttributeError("HTTPClient not found!") + + _all_users: List[User] = [] + + _emoji = ( + f":{emoji.name.replace(':', '')}:{emoji.id or ''}" + if isinstance(emoji, Emoji) + else emoji + ) + + res: List[dict] = await self._client.get_reactions_of_emoji( + channel_id=int(self.channel_id), message_id=int(self.id), emoji=_emoji, limit=100 + ) + + while len(res) == 100: + _after = int(res[-1]["id"]) + _all_users.extend(User(**_) for _ in res) + res: List[dict] = await self._client.get_reactions_of_emoji( + channel_id=int(self.channel_id), + message_id=int(self.id), + emoji=_emoji, + limit=100, + after=_after, + ) + + _all_users.extend(User(**_) for _ in res) + + return _all_users + @classmethod async def get_from_url(cls, url: str, client: "HTTPClient") -> "Message": # noqa, """