diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/moderation/dm_relay.py | 6 | ||||
| -rw-r--r-- | bot/exts/utils/ping.py | 2 | ||||
| -rw-r--r-- | bot/utils/messages.py | 31 | 
3 files changed, 22 insertions, 17 deletions
| diff --git a/bot/exts/moderation/dm_relay.py b/bot/exts/moderation/dm_relay.py index 14263e004..4d5142b55 100644 --- a/bot/exts/moderation/dm_relay.py +++ b/bot/exts/moderation/dm_relay.py @@ -90,7 +90,11 @@ class DMRelay(Cog):          # Handle any attachments          if message.attachments:              try: -                await send_attachments(message, self.webhook) +                await send_attachments( +                    message, +                    self.webhook, +                    username=f"{message.author.display_name} ({message.author.id})" +                )              except (discord.errors.Forbidden, discord.errors.NotFound):                  e = discord.Embed(                      description=":x: **This message contained an attachment, but it could not be retrieved**", diff --git a/bot/exts/utils/ping.py b/bot/exts/utils/ping.py index a9ca3dbeb..572fc934b 100644 --- a/bot/exts/utils/ping.py +++ b/bot/exts/utils/ping.py @@ -33,7 +33,7 @@ class Latency(commands.Cog):          """          # datetime.datetime objects do not have the "milliseconds" attribute.          # It must be converted to seconds before converting to milliseconds. -        bot_ping = (datetime.utcnow() - ctx.message.created_at).total_seconds() / 1000 +        bot_ping = (datetime.utcnow() - ctx.message.created_at).total_seconds() * 1000          bot_ping = f"{bot_ping:.{ROUND_LATENCY}f} ms"          try: diff --git a/bot/utils/messages.py b/bot/utils/messages.py index d0b2342b3..b6c7cab50 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -56,15 +56,24 @@ async def wait_for_deletion(  async def send_attachments(      message: discord.Message,      destination: Union[discord.TextChannel, discord.Webhook], -    link_large: bool = True +    link_large: bool = True, +    use_cached: bool = False, +    **kwargs  ) -> List[str]:      """      Re-upload the message's attachments to the destination and return a list of their new URLs.      Each attachment is sent as a separate message to more easily comply with the request/file size      limit. If link_large is True, attachments which are too large are instead grouped into a single -    embed which links to them. +    embed which links to them. Extra kwargs will be passed to send() when sending the attachment.      """ +    webhook_send_kwargs = { +        'username': message.author.display_name, +        'avatar_url': message.author.avatar_url, +    } +    webhook_send_kwargs.update(kwargs) +    webhook_send_kwargs['username'] = sub_clyde(webhook_send_kwargs['username']) +      large = []      urls = []      for attachment in message.attachments: @@ -78,18 +87,14 @@ async def send_attachments(              # but some may get through hence the try-catch.              if attachment.size <= destination.guild.filesize_limit - 512:                  with BytesIO() as file: -                    await attachment.save(file, use_cached=True) +                    await attachment.save(file, use_cached=use_cached)                      attachment_file = discord.File(file, filename=attachment.filename)                      if isinstance(destination, discord.TextChannel): -                        msg = await destination.send(file=attachment_file) +                        msg = await destination.send(file=attachment_file, **kwargs)                          urls.append(msg.attachments[0].url)                      else: -                        await destination.send( -                            file=attachment_file, -                            username=sub_clyde(message.author.display_name), -                            avatar_url=message.author.avatar_url -                        ) +                        await destination.send(file=attachment_file, **webhook_send_kwargs)              elif link_large:                  large.append(attachment)              else: @@ -106,13 +111,9 @@ async def send_attachments(          embed.set_footer(text="Attachments exceed upload size limit.")          if isinstance(destination, discord.TextChannel): -            await destination.send(embed=embed) +            await destination.send(embed=embed, **kwargs)          else: -            await destination.send( -                embed=embed, -                username=sub_clyde(message.author.display_name), -                avatar_url=message.author.avatar_url -            ) +            await destination.send(embed=embed, **webhook_send_kwargs)      return urls | 
