From 03325a266ff9c53ce2c01d72a5c34643969ea939 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 14 Apr 2024 19:48:02 +0100 Subject: [PATCH] Allow OCRing multiple images --- cogs/other.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/cogs/other.py b/cogs/other.py index 433b958..8fd94de 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -595,24 +595,26 @@ class OtherCog(commands.Cog): @commands.message_command(name="Run OCR") async def message_ocr(self, ctx: discord.ApplicationContext, message: discord.Message): await ctx.defer() - attachment: discord.Attachment | None + + embeds = [] for attachment in message.attachments: if attachment.content_type.startswith("image/"): - break - else: - return await ctx.respond(":x: No images found in message.", delete_after=30) + timings, text = await self._ocr_core(attachment) + embed = discord.Embed( + title="OCR for " + attachment.filename, + description=text, + colour=discord.Colour.blurple(), + url=message.jump_url + ) + embed.set_image(url=attachment.url) + embeds.append(embed) + if len(embeds) == 25: + break - timings, text = await self._ocr_core(attachment) - embed = discord.Embed( - title="OCR for " + attachment.filename, - description=text, - colour=discord.Colour.blurple(), - url=message.jump_url - ) - embed.set_image(url=attachment.url) - await ctx.respond( - embed=embed - ) + if not embeds: + return await ctx.respond(":x: No images found in message.", delete_after=30) + else: + return await ctx.respond(embeds) @commands.message_command(name="Convert Image to GIF") async def convert_image_to_gif(self, ctx: discord.ApplicationContext, message: discord.Message):