From c035a756bac9f2d4c24dc232bda3a6d46b0c8a0f Mon Sep 17 00:00:00 2001 From: wookie184 Date: Fri, 2 Oct 2020 19:52:23 +0100 Subject: Changed send_attachments so kwargs could be given and would be passed to send() --- bot/utils/messages.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/bot/utils/messages.py b/bot/utils/messages.py index d0b2342b3..c4ac1e360 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -56,15 +56,22 @@ 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, + **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': sub_clyde(message.author.display_name), + 'avatar_url': message.author.avatar_url, + } + webhook_send_kwargs.update(kwargs) + large = [] urls = [] for attachment in message.attachments: @@ -82,14 +89,10 @@ async def send_attachments( 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 +109,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 -- cgit v1.2.3 From f7015232947198f2a3d05c680df0da0bfaff4a8e Mon Sep 17 00:00:00 2001 From: wookie184 Date: Fri, 2 Oct 2020 19:55:06 +0100 Subject: Add use_cached argument to send_attachments, and change it to default to False --- bot/utils/messages.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/utils/messages.py b/bot/utils/messages.py index c4ac1e360..9fd571a20 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -57,6 +57,7 @@ async def send_attachments( message: discord.Message, destination: Union[discord.TextChannel, discord.Webhook], link_large: bool = True, + use_cached: bool = False, **kwargs ) -> List[str]: """ @@ -85,7 +86,7 @@ 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): -- cgit v1.2.3 From 1481d8feaa4c155e13da2b1c5f9f9544d89e90c4 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Fri, 2 Oct 2020 19:57:07 +0100 Subject: Changed dm_relay to include user id in webhook when sending attachments. --- bot/exts/moderation/dm_relay.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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**", -- cgit v1.2.3 From 196838d54f8b80f58807eaefe5914467b5581df1 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Wed, 7 Oct 2020 17:15:01 +1000 Subject: Add the ability to purge and ban in one command. --- bot/exts/moderation/infraction/infractions.py | 28 +++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/bot/exts/moderation/infraction/infractions.py b/bot/exts/moderation/infraction/infractions.py index a8b3feb38..9d6de1a97 100644 --- a/bot/exts/moderation/infraction/infractions.py +++ b/bot/exts/moderation/infraction/infractions.py @@ -71,6 +71,23 @@ class Infractions(InfractionScheduler, commands.Cog): """Permanently ban a user for the given reason and stop watching them with Big Brother.""" await self.apply_ban(ctx, user, reason) + @command() + async def purgeban( + self, + ctx: Context, + user: FetchedMember, + purge_days: t.Optional[int] = 1, + *, + reason: t.Optional[str] = None + ) -> None: + """ + Same as ban but removes all their messages for the given number of days, default being 1. + + `purge_days` can only be values between 0 and 7. + Anything outside these bounds are automatically adjusted to their respective limits. + """ + await self.apply_ban(ctx, user, reason, max(min(purge_days, 7), 0)) + # endregion # region: Temporary infractions @@ -246,7 +263,14 @@ class Infractions(InfractionScheduler, commands.Cog): await self.apply_infraction(ctx, infraction, user, action) @respect_role_hierarchy(member_arg=2) - async def apply_ban(self, ctx: Context, user: UserSnowflake, reason: t.Optional[str], **kwargs) -> None: + async def apply_ban( + self, + ctx: Context, + user: UserSnowflake, + reason: t.Optional[str], + purge_days: t.Optional[int] = 0, + **kwargs + ) -> None: """ Apply a ban infraction with kwargs passed to `post_infraction`. @@ -278,7 +302,7 @@ class Infractions(InfractionScheduler, commands.Cog): if reason: reason = textwrap.shorten(reason, width=512, placeholder="...") - action = ctx.guild.ban(user, reason=reason, delete_message_days=0) + action = ctx.guild.ban(user, reason=reason, delete_message_days=purge_days) await self.apply_infraction(ctx, infraction, user, action) if infraction.get('expires_at') is not None: -- cgit v1.2.3 From 64b70160d63d28b1b2b2215cf484a825ca516160 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Wed, 7 Oct 2020 20:06:06 +0100 Subject: made sure to use sub_clyde on username passed to send_attachments --- bot/utils/messages.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 9fd571a20..b6c7cab50 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -68,10 +68,11 @@ async def send_attachments( embed which links to them. Extra kwargs will be passed to send() when sending the attachment. """ webhook_send_kwargs = { - 'username': sub_clyde(message.author.display_name), + '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 = [] -- cgit v1.2.3 From 47b06305f567f0ef2d8cb98c7357910cdb61fbd1 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Thu, 8 Oct 2020 17:11:56 +1000 Subject: Update bot/exts/moderation/infraction/infractions.py Co-authored-by: Dennis Pham --- bot/exts/moderation/infraction/infractions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/moderation/infraction/infractions.py b/bot/exts/moderation/infraction/infractions.py index 9d6de1a97..7cf7075e6 100644 --- a/bot/exts/moderation/infraction/infractions.py +++ b/bot/exts/moderation/infraction/infractions.py @@ -71,7 +71,7 @@ class Infractions(InfractionScheduler, commands.Cog): """Permanently ban a user for the given reason and stop watching them with Big Brother.""" await self.apply_ban(ctx, user, reason) - @command() + @command(aliases=('pban',)) async def purgeban( self, ctx: Context, -- cgit v1.2.3 From 888c427466b370b9ae51e47496e979c2b6faed0c Mon Sep 17 00:00:00 2001 From: Gustav Odinger Date: Thu, 8 Oct 2020 19:35:20 +0200 Subject: Fix millisecond time for command processing time - For the `.ping` command - Fixes a faulty convertion from seconds to milliseconds --- bot/exts/utils/ping.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: -- cgit v1.2.3