Verify that target sizes are sane
This commit is contained in:
parent
0729bce295
commit
02d50180f1
1 changed files with 11 additions and 2 deletions
|
@ -58,6 +58,7 @@ class ImageCog(Scale):
|
|||
async def _resize(
|
||||
self, ctx: InteractionContext, target: str, attachment: Attachment = None, url: str = None
|
||||
) -> None:
|
||||
await ctx.defer()
|
||||
if not attachment and not url:
|
||||
await ctx.send("A URL or attachment is required", ephemeral=True)
|
||||
return
|
||||
|
@ -73,10 +74,18 @@ class ImageCog(Scale):
|
|||
)
|
||||
return
|
||||
|
||||
tgt_size = unconvert_bytesize(float(tgt.groups()[0]), tgt.groups()[1])
|
||||
try:
|
||||
tgt_size = unconvert_bytesize(float(tgt.groups()[0]), tgt.groups()[1])
|
||||
except ValueError:
|
||||
await ctx.send("Failed to read your target size. Try a more sane one", ephemeral=True)
|
||||
return
|
||||
|
||||
if tgt_size > unconvert_bytesize(8, "MB"):
|
||||
await ctx.send("Target too large to send. Please make target < 8MB", ephemeral=True)
|
||||
return
|
||||
elif tgt_size < 1024:
|
||||
await ctx.send("Sizes < 1KB are extremely unreliable and are disabled", ephemeral=True)
|
||||
return
|
||||
|
||||
if attachment:
|
||||
url = attachment.url
|
||||
|
@ -91,7 +100,7 @@ class ImageCog(Scale):
|
|||
|
||||
size = len(data)
|
||||
if size <= tgt_size:
|
||||
await ctx.send("Image already meets target.")
|
||||
await ctx.send("Image already meets target.", ephemeral=True)
|
||||
return
|
||||
|
||||
ratio = max(tgt_size / size - 0.02, 0.50)
|
||||
|
|
Loading…
Add table
Reference in a new issue