Browse Source

Add types to PartialMessage

pull/6836/head
Rapptz 4 years ago
parent
commit
d940486552
  1. 38
      discord/message.py

38
discord/message.py

@ -576,8 +576,9 @@ class Message(Hashable):
'_cs_system_content', '_cs_guild', '_state', 'reactions', 'reference', '_cs_system_content', '_cs_guild', '_state', 'reactions', 'reference',
'application', 'activity', 'stickers') 'application', 'activity', 'stickers')
_HANDLERS: ClassVar[List[Tuple[str, Callable[..., None]]]] if TYPE_CHECKING:
_CACHED_SLOTS: ClassVar[List[str]] _HANDLERS: ClassVar[List[Tuple[str, Callable[..., None]]]]
_CACHED_SLOTS: ClassVar[List[str]]
def __init__(self, *, state: ConnectionState, channel: Union[TextChannel, DMChannel, GroupChannel], data: MessagePayload): def __init__(self, *, state: ConnectionState, channel: Union[TextChannel, DMChannel, GroupChannel], data: MessagePayload):
self._state = state self._state = state
@ -1379,14 +1380,7 @@ class Message(Hashable):
return data return data
def implement_partial_methods(cls):
msg = Message
for name in cls._exported_names:
func = getattr(msg, name)
setattr(cls, name, func)
return cls
@implement_partial_methods
class PartialMessage(Hashable): class PartialMessage(Hashable):
"""Represents a partial message to aid with working messages when only """Represents a partial message to aid with working messages when only
a message and channel ID are present. a message and channel ID are present.
@ -1423,20 +1417,18 @@ class PartialMessage(Hashable):
__slots__ = ('channel', 'id', '_cs_guild', '_state') __slots__ = ('channel', 'id', '_cs_guild', '_state')
_exported_names = ( jump_url: str = Message.jump_url # type: ignore
'jump_url', delete = Message.delete
'delete', publish = Message.publish
'publish', pin = Message.pin
'pin', unpin = Message.unpin
'unpin', add_reaction = Message.add_reaction
'add_reaction', remove_reaction = Message.remove_reaction
'remove_reaction', clear_reaction = Message.clear_reaction
'clear_reaction', clear_reactions = Message.clear_reactions
'clear_reactions', reply = Message.reply
'reply', to_reference = Message.to_reference
'to_reference', to_message_reference_dict = Message.to_message_reference_dict
'to_message_reference_dict',
)
def __init__(self, *, channel: Union[GuildChannel, PrivateChannel], id: int): def __init__(self, *, channel: Union[GuildChannel, PrivateChannel], id: int):
if channel.type not in (ChannelType.text, ChannelType.news, ChannelType.private): if channel.type not in (ChannelType.text, ChannelType.news, ChannelType.private):

Loading…
Cancel
Save