looks like I changed stuff?

This commit is contained in:
iDutchy
2021-06-25 20:29:27 -05:00
78 changed files with 2136 additions and 2539 deletions

View File

@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
"""
The MIT License (MIT)
@@ -33,7 +31,6 @@ from . import utils
from .reaction import Reaction
from .emoji import Emoji
from .partial_emoji import PartialEmoji
from .calls import CallMessage
from .enums import MessageType, ChannelType, try_enum
from .errors import InvalidArgument, ClientException, HTTPException
from .embeds import Embed
@@ -58,7 +55,7 @@ def convert_emoji_reaction(emoji):
emoji = emoji.emoji
if isinstance(emoji, Emoji):
return '%s:%s' % (emoji.name, emoji.id)
return f'{emoji.name}:{emoji.id}'
if isinstance(emoji, PartialEmoji):
return emoji._as_reaction()
if isinstance(emoji, str):
@@ -66,7 +63,7 @@ def convert_emoji_reaction(emoji):
# No existing emojis have <> in them, so this should be okay.
return emoji.strip('<>')
raise InvalidArgument('emoji argument must be str, Emoji, or Reaction not {.__class__.__name__}.'.format(emoji))
raise InvalidArgument(f'emoji argument must be str, Emoji, or Reaction not {emoji.__class__.__name__}.')
class Attachment(Hashable):
"""Represents an attachment from Discord.
@@ -477,12 +474,6 @@ class Message(Hashable):
channel: Union[:class:`abc.Messageable`]
The :class:`TextChannel` that the message was sent from.
Could be a :class:`DMChannel` or :class:`GroupChannel` if it's a private message.
call: Optional[:class:`CallMessage`]
The call that the message refers to. This is only applicable to messages of type
:attr:`MessageType.call`.
.. deprecated:: 1.7
reference: Optional[:class:`~discord.MessageReference`]
The message that this message references. This is only applicable to messages of
type :attr:`MessageType.pins_add`, crossposted messages created by a
@@ -558,7 +549,7 @@ class Message(Hashable):
'mention_everyone', 'embeds', 'id', 'mentions', 'author',
'_cs_channel_mentions', '_cs_raw_mentions', 'attachments',
'_cs_clean_content', '_cs_raw_channel_mentions', 'nonce', 'pinned',
'role_mentions', '_cs_raw_role_mentions', 'type', 'call', 'flags',
'role_mentions', '_cs_raw_role_mentions', 'type', 'flags',
'_cs_system_content', '_cs_guild', '_state', 'reactions', 'reference',
'application', 'activity', 'stickers')
@@ -572,7 +563,6 @@ class Message(Hashable):
self.application = data.get('application')
self.activity = data.get('activity')
self.channel = channel
self.call = None
self._edited_timestamp = utils.parse_time(data['edited_timestamp'])
self.type = try_enum(MessageType, data['type'])
self.pinned = data['pinned']
@@ -605,9 +595,9 @@ class Message(Hashable):
ref.resolved = self.__class__(channel=chan, data=resolved, state=state)
for handler in ('author', 'member', 'mentions', 'mention_roles', 'call', 'flags'):
for handler in ('author', 'member', 'mentions', 'mention_roles', 'flags'):
try:
getattr(self, '_handle_%s' % handler)(data[handler])
getattr(self, f'_handle_{handler}')(data[handler])
except KeyError:
continue
@@ -779,26 +769,6 @@ class Message(Hashable):
if role is not None:
self.role_mentions.append(role)
def _handle_call(self, call):
if call is None or self.type is not MessageType.call:
self.call = None
return
# we get the participant source from the mentions array or
# the author
participants = []
for uid in map(int, call.get('participants', [])):
if uid == self.author.id:
participants.append(self.author)
else:
user = utils.find(lambda u: u.id == uid, self.mentions)
if user is not None:
participants.append(user)
call['participants'] = participants
self.call = CallMessage(message=self, **call)
def _rebind_channel_reference(self, new_channel):
self.channel = new_channel
@@ -856,23 +826,23 @@ class Message(Hashable):
.. note::
This *does not* affect markdown. If you want to escape
or remove markdown then use :func:`utils.escape_markdown` or :func:`utils.remove_markdown`
or remove markdown then use :func:`utils.escape_markdown` or :func:`utils.remove_markdown`
respectively, along with this function.
"""
transformations = {
re.escape('<#%s>' % channel.id): '#' + channel.name
re.escape(f'<#{channel.id}>'): '#' + channel.name
for channel in self.channel_mentions
}
mention_transforms = {
re.escape('<@%s>' % member.id): '@' + member.display_name
re.escape(f'<@{member.id}>'): '@' + member.display_name
for member in self.mentions
}
# add the <@!user_id> cases as well..
second_mention_transforms = {
re.escape('<@!%s>' % member.id): '@' + member.display_name
re.escape(f'<@!{member.id}>'): '@' + member.display_name
for member in self.mentions
}
@@ -881,7 +851,7 @@ class Message(Hashable):
if self.guild is not None:
role_transforms = {
re.escape('<@&%s>' % role.id): '@' + role.name
re.escape(f'<@&{role.id}>'): '@' + role.name
for role in self.role_mentions
}
transformations.update(role_transforms)
@@ -900,7 +870,7 @@ class Message(Hashable):
@property
def edited_at(self):
"""Optional[:class:`datetime.datetime`]: A naive UTC datetime object containing the edited time of the message."""
"""Optional[:class:`datetime.datetime`]: An aware UTC datetime object containing the edited time of the message."""
return self._edited_timestamp
@property
@@ -930,7 +900,7 @@ class Message(Hashable):
return self.content
if self.type is MessageType.pins_add:
return '{0.name} pinned a message to this channel.'.format(self.author)
return f'{self.author.name} pinned a message to this channel.'
if self.type is MessageType.recipient_add:
return '{0.name} added {1.name} to the group.'.format(self.author, self.mentions[0])
@@ -942,7 +912,7 @@ class Message(Hashable):
return '{0.author.name} changed the channel name: {0.content}'.format(self)
if self.type is MessageType.channel_icon_change:
return '{0.author.name} changed the channel icon.'.format(self)
return f'{self.author.name} changed the channel icon.'
if self.type is MessageType.new_member:
formats = [
@@ -961,27 +931,11 @@ class Message(Hashable):
"Yay you made it, {0}!",
]
# manually reconstruct the epoch with millisecond precision, because
# datetime.datetime.timestamp() doesn't return the exact posix
# timestamp with the precision that we need
created_at_ms = int((self.created_at - datetime.datetime(1970, 1, 1)).total_seconds() * 1000)
created_at_ms = int(self.created_at.timestamp() * 1000)
return formats[created_at_ms % len(formats)].format(self.author.name)
if self.type is MessageType.call:
# we're at the call message type now, which is a bit more complicated.
# we can make the assumption that Message.channel is a PrivateChannel
# with the type ChannelType.group or ChannelType.private
call_ended = self.call.ended_timestamp is not None
if self.channel.me in self.call.participants:
return '{0.author.name} started a call.'.format(self)
elif call_ended:
return 'You missed a call from {0.author.name}'.format(self)
else:
return '{0.author.name} started a call \N{EM DASH} Join the call.'.format(self)
if self.type is MessageType.premium_guild_subscription:
return '{0.author.name} just boosted the server!'.format(self)
return f'{self.author.name} just boosted the server!'
if self.type is MessageType.premium_guild_tier_1:
return '{0.author.name} just boosted the server! {0.guild} has achieved **Level 1!**'.format(self)
@@ -1050,7 +1004,7 @@ class Message(Hashable):
except HTTPException:
pass
asyncio.ensure_future(delete(), loop=self._state.loop)
asyncio.create_task(delete())
else:
try:
await self._state.http.delete_message(self.channel.id, self.id)
@@ -1344,29 +1298,6 @@ class Message(Hashable):
"""
await self._state.http.clear_reactions(self.channel.id, self.id)
@utils.deprecated()
async def ack(self):
"""|coro|
Marks this message as read.
The user must not be a bot user.
.. deprecated:: 1.7
Raises
-------
HTTPException
Acking failed.
ClientException
You must not be a bot user.
"""
state = self._state
if state.is_bot:
raise ClientException('Must not be a bot account to ack messages.')
return await state.http.ack_message(self.channel.id, self.id)
async def reply(self, content=None, **kwargs):
"""|coro|
@@ -1486,7 +1417,7 @@ class PartialMessage(Hashable):
def __init__(self, *, channel, id):
if channel.type not in (ChannelType.text, ChannelType.news, ChannelType.private):
raise TypeError('Expected TextChannel or DMChannel not %r' % type(channel))
raise TypeError(f'Expected TextChannel or DMChannel not {type(channel)!r}')
self.channel = channel
self._state = channel._state