meme cog: Don't convert images if already in PNG format; sing cog: remove ephemeral=True from bridge s/sing command initial response; misc_util: remove 2 coffees
This commit is contained in:
		
							
								
								
									
										25
									
								
								cogs/meme.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								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: | ||||
|         """ | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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 = [] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user