File size limit on image sending
This commit is contained in:
parent
b3d1bd3a22
commit
94d0594361
1 changed files with 10 additions and 4 deletions
|
@ -39,16 +39,24 @@ class ImageCog(commands.Cog):
|
|||
return
|
||||
|
||||
tgt_size = unconvert_bytesize(float(tgt.groups()[0]), tgt.groups()[1])
|
||||
if tgt_size > unconvert_bytesize(8, "MB"):
|
||||
await ctx.send(
|
||||
"Target too large to send. Please make target < 8MB"
|
||||
)
|
||||
return
|
||||
file = None
|
||||
filename = None
|
||||
if (
|
||||
ctx.message.attachments is not None
|
||||
and len(ctx.message.attachments) > 0
|
||||
):
|
||||
file = await ctx.message.attachments[0].read()
|
||||
filename = ctx.message.attachments[0].filename
|
||||
elif url is not None:
|
||||
async with self._session.get(url) as resp:
|
||||
if resp.status == 200:
|
||||
file = await resp.read()
|
||||
filename = url.split("/")[-1]
|
||||
else:
|
||||
ctx.send("Missing file as either attachment or URL.")
|
||||
|
||||
|
@ -79,10 +87,8 @@ class ImageCog(commands.Cog):
|
|||
Field("New Size", convert_bytesize(len(file)), False),
|
||||
Field("Accuracy", f"{accuracy:.02f}%", False),
|
||||
]
|
||||
embed = build_embed(
|
||||
title="Image Resize Utility", desc=None, fields=fields
|
||||
)
|
||||
embed.set_image(url="attachment://resized.png")
|
||||
embed = build_embed(title=filename, desc=None, fields=fields)
|
||||
embed.set_image(url=f"attachment://resized.png")
|
||||
await ctx.send(
|
||||
embed=embed,
|
||||
file=File(bufio, filename="resized.png"),
|
||||
|
|
Loading…
Add table
Reference in a new issue