Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protect|logger: account for file size limit #591

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions techsupport_bot/extensions/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,17 @@ async def response(self, config, ctx, _, __):
)
return

attachments = []
attachments: list[discord.File] = []
if ctx.message.attachments:
attachments = [await attch.to_file() for attch in ctx.message.attachments]
total_attachment_size = 0
for attch in ctx.message.attachments:
if (
total_attachment_size := total_attachment_size + attch.size
) <= ctx.filesize_limit:
attachments.append(await attch.to_file())
if (lf := len(ctx.message.attachments) - len(attachments)) != 0:
await self.bot.logger.info(
f"Did not reupload {lf} file(s) due to file size limit."
)

await channel.send(embed=LogEmbed(context=ctx), files=attachments[:10])
15 changes: 12 additions & 3 deletions techsupport_bot/extensions/protect.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,20 @@ def max_newlines(self, max_length):
"""Method to set up the number of max lines."""
return int(max_length / self.CHARS_PER_NEWLINE) + 1

async def handle_length_alert(self, config, ctx, content):
async def handle_length_alert(self, config, ctx, content) -> None:
"""Method to handle alert for the protect extension."""
attachments = []
attachments: list[discord.File] = []
if ctx.message.attachments:
attachments = [await attch.to_file() for attch in ctx.message.attachments]
total_attachment_size = 0
for attch in ctx.message.attachments:
if (
total_attachment_size := total_attachment_size + attch.size
) <= ctx.filesize_limit:
attachments.append(await attch.to_file())
if (lf := len(ctx.message.attachments) - len(attachments)) != 0:
await self.bot.logger.info(
f"Did not reupload {lf} file(s) due to file size limit."
)
await ctx.message.delete()

reason = "message too long (too many newlines or characters)"
Expand Down
Loading