From 920f8817d75c26df7f6042e181c3ddcab7702b49 Mon Sep 17 00:00:00 2001 From: bobloy Date: Mon, 15 Mar 2021 10:15:13 -0400 Subject: [PATCH] Use guild.id and author.id for file name, support using jpg --- qrinvite/qrinvite.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qrinvite/qrinvite.py b/qrinvite/qrinvite.py index a91f7ab..a4c377c 100644 --- a/qrinvite/qrinvite.py +++ b/qrinvite/qrinvite.py @@ -68,7 +68,7 @@ class QRInvite(Cog): extension = pathlib.Path(image_url).parts[-1].replace(".", "?").split("?")[1] path: pathlib.Path = cog_data_path(self) - image_path = path / (ctx.guild.icon + "." + extension) + image_path = path / f"{ctx.guild.id}-{ctx.author.id}.{extension}" async with aiohttp.ClientSession() as session: async with session.get(image_url) as response: image = await response.read() @@ -83,6 +83,8 @@ class QRInvite(Cog): return elif extension == "png": new_path = str(image_path) + elif extension == "jpg": + new_path = convert_jpg_to_png(str(image_path)) else: await ctx.maybe_send_embed(f"{extension} is not supported yet, stay tuned") return @@ -110,3 +112,10 @@ def convert_webp_to_png(path): new_path = path.replace(".webp", ".png") im.save(new_path, transparency=255) return new_path + + +def convert_jpg_to_png(path): + im = Image.open(path) + new_path = path.replace(".jpg", ".png") + im.save(new_path) + return new_path