stop uploading ocr content as a file

This commit is contained in:
Nexus 2023-08-28 19:43:25 +01:00
parent 94ebc95550
commit f1eed7871f

View file

@ -898,6 +898,7 @@ class OtherCog(commands.Cog):
formats[fmt].get("acodec", 'N/A'),
formats[fmt].get("vcodec", 'N/A'),
f"{round(fs, 2)}{units[0]}"
)
),
colour=discord.Colour.blurple()
).add_field(
@ -1392,7 +1393,7 @@ class OtherCog(commands.Cog):
)
await ctx.respond(embed=embed)
timings["Upload text to mystbin"] = _t.total
elif len(text) <= 1500 and text.count("\n") <= 7:
elif len(text) <= 1500:
with Timer() as _t:
await ctx.respond(embed=discord.Embed(description=text))
timings["Respond (Text)"] = _t.total
@ -1408,48 +1409,6 @@ class OtherCog(commands.Cog):
content=text,
)
@commands.slash_command(name="image-to-gif")
@commands.cooldown(1, 30, commands.BucketType.user)
@commands.max_concurrency(1, commands.BucketType.user)
async def convert_image_to_gif(
self,
ctx: discord.ApplicationContext,
image: discord.Option(
discord.SlashCommandOptionType.attachment,
description="Image to convert. PNG/JPEG only.",
),
backup: discord.Option(
discord.SlashCommandOptionType.boolean,
description="Sends the GIF to your DM as well so you'll never lose it.",
default=False
)
):
"""Converts a static image to a gif, so you can save it"""
await ctx.defer()
image: discord.Attachment
with tempfile.TemporaryFile("wb+") as f:
await image.save(f)
f.seek(0)
img = await self.bot.loop.run_in_executor(None, Image.open, f)
if img.format.upper() not in ("PNG", "JPEG", "WEBP", "HEIF", "BMP", "TIFF"):
return await ctx.respond("Image must be PNG, JPEG, WEBP, or HEIF.")
with tempfile.TemporaryFile("wb+") as f2:
caller = partial(img.save, f2, format="GIF")
await self.bot.loop.run_in_executor(None, caller)
f2.seek(0)
try:
await ctx.respond(file=discord.File(f2, filename="image.gif"))
except discord.HTTPException as e:
if e.code == 40005:
return await ctx.respond("Image is too large.")
return await ctx.respond(f"Failed to upload: `{e}`")
if backup:
try:
await ctx.user.send(file=discord.File(f2, filename="image.gif"))
except discord.Forbidden:
return await ctx.respond("Unable to mirror to your DM - am I blocked?", ephemeral=True)
@commands.message_command(name="Convert Image to GIF")
async def convert_image_to_gif(self, ctx: discord.ApplicationContext, message: discord.Message):
await ctx.defer()