Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions interactions/api/http/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,35 @@ 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.

: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,
Expand Down
2 changes: 1 addition & 1 deletion interactions/api/http/reaction.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
66 changes: 66 additions & 0 deletions interactions/api/models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
"""
Expand Down