mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
stop uploading ocr content as a file
This commit is contained in:
parent
94ebc95550
commit
f1eed7871f
1 changed files with 2 additions and 43 deletions
|
@ -898,6 +898,7 @@ class OtherCog(commands.Cog):
|
||||||
formats[fmt].get("acodec", 'N/A'),
|
formats[fmt].get("acodec", 'N/A'),
|
||||||
formats[fmt].get("vcodec", 'N/A'),
|
formats[fmt].get("vcodec", 'N/A'),
|
||||||
f"{round(fs, 2)}{units[0]}"
|
f"{round(fs, 2)}{units[0]}"
|
||||||
|
)
|
||||||
),
|
),
|
||||||
colour=discord.Colour.blurple()
|
colour=discord.Colour.blurple()
|
||||||
).add_field(
|
).add_field(
|
||||||
|
@ -1392,7 +1393,7 @@ class OtherCog(commands.Cog):
|
||||||
)
|
)
|
||||||
await ctx.respond(embed=embed)
|
await ctx.respond(embed=embed)
|
||||||
timings["Upload text to mystbin"] = _t.total
|
timings["Upload text to mystbin"] = _t.total
|
||||||
elif len(text) <= 1500 and text.count("\n") <= 7:
|
elif len(text) <= 1500:
|
||||||
with Timer() as _t:
|
with Timer() as _t:
|
||||||
await ctx.respond(embed=discord.Embed(description=text))
|
await ctx.respond(embed=discord.Embed(description=text))
|
||||||
timings["Respond (Text)"] = _t.total
|
timings["Respond (Text)"] = _t.total
|
||||||
|
@ -1408,48 +1409,6 @@ class OtherCog(commands.Cog):
|
||||||
content=text,
|
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")
|
@commands.message_command(name="Convert Image to GIF")
|
||||||
async def convert_image_to_gif(self, ctx: discord.ApplicationContext, message: discord.Message):
|
async def convert_image_to_gif(self, ctx: discord.ApplicationContext, message: discord.Message):
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
|
Loading…
Reference in a new issue