mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-05 17:41:53 +00:00
Typehint Reaction
This commit is contained in:
parent
9181bf046b
commit
c251c51cb1
@ -22,12 +22,22 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
from typing import Any, TYPE_CHECKING, Union, Optional
|
||||||
|
|
||||||
from .iterators import ReactionIterator
|
from .iterators import ReactionIterator
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Reaction',
|
'Reaction',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .types.message import Reaction as ReactionPayload
|
||||||
|
from .message import Message
|
||||||
|
from .partial_emoji import PartialEmoji
|
||||||
|
from .emoji import Emoji
|
||||||
|
from .abc import Snowflake
|
||||||
|
|
||||||
class Reaction:
|
class Reaction:
|
||||||
"""Represents a reaction to a message.
|
"""Represents a reaction to a message.
|
||||||
|
|
||||||
@ -67,34 +77,35 @@ class Reaction:
|
|||||||
"""
|
"""
|
||||||
__slots__ = ('message', 'count', 'emoji', 'me')
|
__slots__ = ('message', 'count', 'emoji', 'me')
|
||||||
|
|
||||||
def __init__(self, *, message, data, emoji=None):
|
def __init__(self, *, message: Message, data: ReactionPayload, emoji: Optional[Union[PartialEmoji, Emoji, str]] = None):
|
||||||
self.message = message
|
self.message: Message = message
|
||||||
self.emoji = 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 = data.get('count', 1)
|
self.count: int = data.get('count', 1)
|
||||||
self.me = data.get('me')
|
self.me: bool = data.get('me')
|
||||||
|
|
||||||
def is_custom_emoji(self):
|
# TODO: typeguard
|
||||||
|
def is_custom_emoji(self) -> bool:
|
||||||
""":class:`bool`: If this is a custom emoji."""
|
""":class:`bool`: If this is a custom emoji."""
|
||||||
return not isinstance(self.emoji, str)
|
return not isinstance(self.emoji, str)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other: Any) -> bool:
|
||||||
return isinstance(other, self.__class__) and other.emoji == self.emoji
|
return isinstance(other, self.__class__) and other.emoji == self.emoji
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other: Any) -> bool:
|
||||||
if isinstance(other, self.__class__):
|
if isinstance(other, self.__class__):
|
||||||
return other.emoji != self.emoji
|
return other.emoji != self.emoji
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self) -> int:
|
||||||
return hash(self.emoji)
|
return hash(self.emoji)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return str(self.emoji)
|
return str(self.emoji)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self) -> str:
|
||||||
return f'<Reaction emoji={self.emoji!r} me={self.me} count={self.count}>'
|
return f'<Reaction emoji={self.emoji!r} me={self.me} count={self.count}>'
|
||||||
|
|
||||||
async def remove(self, user):
|
async def remove(self, user: Snowflake) -> None:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Remove the reaction by the provided :class:`User` from the message.
|
Remove the reaction by the provided :class:`User` from the message.
|
||||||
@ -122,7 +133,7 @@ class Reaction:
|
|||||||
|
|
||||||
await self.message.remove_reaction(self.emoji, user)
|
await self.message.remove_reaction(self.emoji, user)
|
||||||
|
|
||||||
async def clear(self):
|
async def clear(self) -> None:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Clears this reaction from the message.
|
Clears this reaction from the message.
|
||||||
@ -144,7 +155,7 @@ class Reaction:
|
|||||||
"""
|
"""
|
||||||
await self.message.clear_reaction(self.emoji)
|
await self.message.clear_reaction(self.emoji)
|
||||||
|
|
||||||
def users(self, limit=None, after=None):
|
def users(self, limit: Optional[int] = None, after: Optional[Snowflake] = None) -> ReactionIterator:
|
||||||
"""Returns an :class:`AsyncIterator` representing the users that have reacted to the message.
|
"""Returns an :class:`AsyncIterator` representing the users that have reacted to the message.
|
||||||
|
|
||||||
The ``after`` parameter must represent a member
|
The ``after`` parameter must represent a member
|
||||||
@ -168,11 +179,11 @@ class Reaction:
|
|||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
------------
|
------------
|
||||||
limit: :class:`int`
|
limit: Optional[:class:`int`]
|
||||||
The maximum number of results to return.
|
The maximum number of results to return.
|
||||||
If not provided, returns all the users who
|
If not provided, returns all the users who
|
||||||
reacted to the message.
|
reacted to the message.
|
||||||
after: :class:`abc.Snowflake`
|
after: Optional[:class:`abc.Snowflake`]
|
||||||
For pagination, reactions are sorted by member.
|
For pagination, reactions are sorted by member.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
|
Loading…
x
Reference in New Issue
Block a user