diff --git a/README.md b/README.md
index a264b4b..4f1e786 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,8 @@ Cog Function
| secrethitler | **Incomplete** | Play the Secret Hitler game
Concept, no work done yet |
| stealemoji | **Alpha** | Steals any custom emoji it sees in a reaction
Some planned upgrades for server generation |
| timerole | **Alpha** | Add roles to members after specified time on the server
Upgraded from V2, please report any bugs |
-| tts | **Alpha** | Send a Text-to-Speech message as an uploaded mp3
Initial release, please report any bugs |
+| tts | **Alpha** | Send a Text-to-Speech message as an uploaded mp3
Alpha release, please report any bugs |
+| qrinvite | **Alpha** | Create a QR code invite for the server
Alpha release, please report any bugs |
| werewolf | **Alpha** | Play the classic party game Werewolf within discord
Another massive project currently being developed, will be fully customizable |
diff --git a/qrinvite/__init__.py b/qrinvite/__init__.py
new file mode 100644
index 0000000..a91023a
--- /dev/null
+++ b/qrinvite/__init__.py
@@ -0,0 +1,5 @@
+from .qrinvite import QRInvite
+
+
+def setup(bot):
+ bot.add_cog(QRInvite(bot))
diff --git a/qrinvite/info..json b/qrinvite/info..json
new file mode 100644
index 0000000..3015652
--- /dev/null
+++ b/qrinvite/info..json
@@ -0,0 +1,23 @@
+{
+ "author": [
+ "Bobloy"
+ ],
+ "bot_version": [
+ 3,
+ 0,
+ 0
+ ],
+ "description": "Create a QR code invite for the server",
+ "hidden": true,
+ "install_msg": "Thank you for installing QRInvite! Get started with `[p]help QRInvite`",
+ "requirements": [
+ "MyQR"
+ ],
+ "short": "Create a QR code invite",
+ "tags": [
+ "bobloy",
+ "tools",
+ "qr",
+ "code"
+ ]
+}
\ No newline at end of file
diff --git a/qrinvite/qrinvite.py b/qrinvite/qrinvite.py
new file mode 100644
index 0000000..4180bb4
--- /dev/null
+++ b/qrinvite/qrinvite.py
@@ -0,0 +1,81 @@
+import pathlib
+
+import aiohttp
+import discord
+from PIL import Image
+
+from redbot.core import Config, checks, commands
+
+from redbot.core.bot import Red
+
+from MyQR import myqr
+from redbot.core.data_manager import cog_data_path
+
+
+class QRInvite:
+ """
+ V3 Cog Template
+ """
+
+ def __init__(self, bot: Red):
+ self.bot = bot
+ self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True)
+ default_global = {}
+ default_guild = {}
+
+ self.config.register_global(**default_global)
+ self.config.register_guild(**default_guild)
+
+ @commands.command()
+ async def qrinvite(self, ctx: commands.Context, invite: str=None, colorized: bool=False, image_url: str=None):
+ """
+ Create a custom QR code invite for this server
+ """
+ if invite is None:
+ try:
+ invite = await ctx.channel.create_invite()
+ except discord.Forbidden:
+ try:
+ invite = await ctx.channel.invites()
+ invite = invite[0]
+ except discord.Forbidden:
+ await ctx.send("No permission to get an invite, please provide one")
+ return
+ invite = invite.code
+
+ if image_url is None:
+ image_url = ctx.guild.icon_url
+
+ extension = pathlib.Path(image_url).parts[-1].replace('.','?').split('?')[1]
+
+ path: pathlib.Path = cog_data_path(self)
+ image_path = path / (ctx.guild.icon+"."+extension)
+ async with aiohttp.ClientSession() as session:
+ async with session.get(image_url) as response:
+ image = await response.read()
+
+ with image_path.open("wb") as file:
+ file.write(image)
+
+ if extension == "webp":
+ new_path = convert_png(str(image_path))
+ else:
+ new_path = str(image_path)
+
+ myqr.run(invite,picture=new_path,save_name=ctx.guild.icon+"_qrcode.png",
+ save_dir=str(cog_data_path(self)),colorized=colorized,)
+
+ png_path: pathlib.Path = path / (ctx.guild.icon+"_qrcode.png")
+ with png_path.open("rb") as png_fp:
+ await ctx.send(file=discord.File(png_fp.read(), "qrcode.png"))
+
+def convert_png(path):
+ im = Image.open(path)
+ im.load()
+ alpha = im.split()[-1]
+ im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=255)
+ mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0)
+ im.paste(255, mask)
+ newPath = path.replace(".webp",".png")
+ im.save(newPath, transparency=255)
+ return newPath
\ No newline at end of file