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
|
return
|
||||||
|
|
||||||
tgt_size = unconvert_bytesize(float(tgt.groups()[0]), tgt.groups()[1])
|
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
|
file = None
|
||||||
|
filename = None
|
||||||
if (
|
if (
|
||||||
ctx.message.attachments is not None
|
ctx.message.attachments is not None
|
||||||
and len(ctx.message.attachments) > 0
|
and len(ctx.message.attachments) > 0
|
||||||
):
|
):
|
||||||
file = await ctx.message.attachments[0].read()
|
file = await ctx.message.attachments[0].read()
|
||||||
|
filename = ctx.message.attachments[0].filename
|
||||||
elif url is not None:
|
elif url is not None:
|
||||||
async with self._session.get(url) as resp:
|
async with self._session.get(url) as resp:
|
||||||
if resp.status == 200:
|
if resp.status == 200:
|
||||||
file = await resp.read()
|
file = await resp.read()
|
||||||
|
filename = url.split("/")[-1]
|
||||||
else:
|
else:
|
||||||
ctx.send("Missing file as either attachment or URL.")
|
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("New Size", convert_bytesize(len(file)), False),
|
||||||
Field("Accuracy", f"{accuracy:.02f}%", False),
|
Field("Accuracy", f"{accuracy:.02f}%", False),
|
||||||
]
|
]
|
||||||
embed = build_embed(
|
embed = build_embed(title=filename, desc=None, fields=fields)
|
||||||
title="Image Resize Utility", desc=None, fields=fields
|
embed.set_image(url=f"attachment://resized.png")
|
||||||
)
|
|
||||||
embed.set_image(url="attachment://resized.png")
|
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
embed=embed,
|
embed=embed,
|
||||||
file=File(bufio, filename="resized.png"),
|
file=File(bufio, filename="resized.png"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue