QR invite fixes
This commit is contained in:
parent
eecfb821a0
commit
50a61398e6
@ -2,13 +2,10 @@ import pathlib
|
|||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import discord
|
import discord
|
||||||
from PIL import Image
|
|
||||||
|
|
||||||
from redbot.core import Config, checks, commands
|
|
||||||
|
|
||||||
from redbot.core.bot import Red
|
|
||||||
|
|
||||||
from MyQR import myqr
|
from MyQR import myqr
|
||||||
|
from PIL import Image
|
||||||
|
from redbot.core import Config, commands
|
||||||
|
from redbot.core.bot import Red
|
||||||
from redbot.core.data_manager import cog_data_path
|
from redbot.core.data_manager import cog_data_path
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +24,7 @@ class QRInvite:
|
|||||||
self.config.register_guild(**default_guild)
|
self.config.register_guild(**default_guild)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def qrinvite(self, ctx: commands.Context, invite: str=None, colorized: bool=False, image_url: str=None):
|
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
|
Create a custom QR code invite for this server
|
||||||
"""
|
"""
|
||||||
@ -46,10 +43,15 @@ class QRInvite:
|
|||||||
if image_url is None:
|
if image_url is None:
|
||||||
image_url = ctx.guild.icon_url
|
image_url = ctx.guild.icon_url
|
||||||
|
|
||||||
extension = pathlib.Path(image_url).parts[-1].replace('.','?').split('?')[1]
|
if image_url == "": # Still
|
||||||
|
await ctx.send(
|
||||||
|
"Could not get an image, please provide one. *(`{}help qrinvite` for details)*".format(ctx.prefix))
|
||||||
|
return
|
||||||
|
|
||||||
|
extension = pathlib.Path(image_url).parts[-1].replace('.', '?').split('?')[1]
|
||||||
|
|
||||||
path: pathlib.Path = cog_data_path(self)
|
path: pathlib.Path = cog_data_path(self)
|
||||||
image_path = path / (ctx.guild.icon+"."+extension)
|
image_path = path / (ctx.guild.icon + "." + extension)
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(image_url) as response:
|
async with session.get(image_url) as response:
|
||||||
image = await response.read()
|
image = await response.read()
|
||||||
@ -62,20 +64,21 @@ class QRInvite:
|
|||||||
else:
|
else:
|
||||||
new_path = str(image_path)
|
new_path = str(image_path)
|
||||||
|
|
||||||
myqr.run(invite,picture=new_path,save_name=ctx.guild.icon+"_qrcode.png",
|
myqr.run(invite, picture=new_path, save_name=ctx.guild.icon + "_qrcode.png",
|
||||||
save_dir=str(cog_data_path(self)),colorized=colorized,)
|
save_dir=str(cog_data_path(self)), colorized=colorized, )
|
||||||
|
|
||||||
png_path: pathlib.Path = path / (ctx.guild.icon+"_qrcode.png")
|
png_path: pathlib.Path = path / (ctx.guild.icon + "_qrcode.png")
|
||||||
with png_path.open("rb") as png_fp:
|
with png_path.open("rb") as png_fp:
|
||||||
await ctx.send(file=discord.File(png_fp.read(), "qrcode.png"))
|
await ctx.send(file=discord.File(png_fp.read(), "qrcode.png"))
|
||||||
|
|
||||||
|
|
||||||
def convert_png(path):
|
def convert_png(path):
|
||||||
im = Image.open(path)
|
im = Image.open(path)
|
||||||
im.load()
|
im.load()
|
||||||
alpha = im.split()[-1]
|
alpha = im.split()[-1]
|
||||||
im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=255)
|
im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=255)
|
||||||
mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0)
|
mask = Image.eval(alpha, lambda a: 255 if a <= 128 else 0)
|
||||||
im.paste(255, mask)
|
im.paste(255, mask)
|
||||||
newPath = path.replace(".webp",".png")
|
new_path = path.replace(".webp", ".png")
|
||||||
im.save(newPath, transparency=255)
|
im.save(new_path, transparency=255)
|
||||||
return newPath
|
return new_path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user