diff --git a/cogs/meme.py b/cogs/meme.py index 25b6dac..fd46d59 100644 --- a/cogs/meme.py +++ b/cogs/meme.py @@ -264,10 +264,13 @@ class Meme(commands.Cog): phash: str = str(imagehash.phash(_image)) query: str = "INSERT INTO memes(discord_uid, timestamp, image, message_ids, phash) VALUES(?, ?, ?, ?, ?)" image.seek(0) - converted = self.convert_to_png(image) + if not self.is_png(image): + store_image = self.convert_to_png(image) + else: + store_image = image.read() async with sqlite3.connect(self.meme_db_path, timeout=5) as db_conn: insert = await db_conn.execute_insert( - query, (discord_uid, timestamp, converted, message_id, phash) + query, (discord_uid, timestamp, store_image, message_id, phash) ) if insert: await db_conn.commit() @@ -860,6 +863,24 @@ class Meme(commands.Cog): else: await ctx.respond("NO embed :(") + def is_png(self, buffer: bytes | io.BytesIO) -> bool: + """ + Check if image (in-memory buffer, or bytes) is a PNG + Args: + buffer (bytes|io.BytesIO) + Returns: + bool + """ + # Accepts either bytes or a BytesIO-like object + if isinstance(buffer, io.BytesIO): + if hasattr(buffer, "read") and hasattr(buffer, "seek"): + pos = buffer.tell() + buffer.seek(0) + signature = buffer.read(8) + buffer.seek(pos) + else: + signature = buffer[:8] + return signature == b"\x89PNG\r\n\x1a\n" def convert_to_png(self, in_buffer: io.BytesIO) -> bytes: """ diff --git a/cogs/sing.py b/cogs/sing.py index 862d8a0..27429ed 100644 --- a/cogs/sing.py +++ b/cogs/sing.py @@ -61,7 +61,7 @@ class Sing(commands.Cog): ) await ctx.respond( - "*Searching...*", ephemeral=True + "*Searching...*" ) # Must respond to interactions within 3 seconds, per Discord parsed = self.utility.parse_song_input(song, activity) diff --git a/util/misc_util.py b/util/misc_util.py index 36749b5..d7a0d78 100644 --- a/util/misc_util.py +++ b/util/misc_util.py @@ -115,8 +115,6 @@ class Util: "a sweet cream cold brew", "a matcha latte", "a golden latte", - "a turmeric latte", - "a beetroot latte", "a kopi luwak", ] self.LAST_5_COFFEES: list = []