async def colorinfo(self, ctx, color): color = color.strip('#') changePNGColor("db/images/normal-circle.png", "#FFFFFF", f"#{color}") embed=discord.Embed() async with aiohttp.ClientSession() as cs: async with cs.get(f'http://thecolorapi.com/id?hex={color}') as r: res = await r.json() hex = res['hex']['value'] rgb = f"({res['rgb']['r']}, {res['rgb']['g']}, {res['rgb']['b']})" hsl = f"({res['hsl']['h']}, {res['hsl']['s']}%, {res['hsl']['l']}%)" hsv = f"({res['hsv']['h']}, {res['hsv']['s']}%, {res['hsv']['v']}%)" name = res['name']['value'] cmyk = f"({res['cmyk']['c']}, {res['cmyk']['m']}, {res['cmyk']['y']}, {res['cmyk']['k']})" xyz = f"({res['XYZ']['X']}, {res['XYZ']['Y']}, {res['XYZ']['Z']})" f = discord.File(f"db/images/{color}.png", filename="image.png") embed.set_thumbnail(url="attachment://image.png") embed.title = name embed.color = discord.Color(int(f"0x{color}", 16)) embed.add_field(name="Hex", value=hex) embed.add_field(name="rgb", value=rgb) embed.add_field(name="cmyk", value=cmyk) embed.add_field(name="hsv", value=hsv) embed.add_field(name="hsl", value=hsl) embed.add_field(name="XYZ", value=xyz) await ctx.send(embed=embed, file=f) os.remove(f"db/images/{color}.png")
async def randomcolor(self, ctx): r = lambda: random.randint(0,255) color = f"{f'{r():x}':0>2}{f'{r():x}':0>2}{f'{r():x}':0>2}" embed=discord.Embed(color=discord.Color(int(f"0x{color}", 16))) embed.add_field(name="Hex", value=f"#{color}") changePNGColor("db/images/circle.png", "#FFFFFF", f"#{color}") lv = len(color) rgb_color = tuple(int(color[i:i + lv // 3], 16) for i in range(0, lv, lv // 3)) embed.add_field(name="RGB", value=rgb_color, inline=False) f = discord.File(f"db/images/{color}.png", filename="image.png") embed.set_thumbnail(url="attachment://image.png") info_cmd = f"{ctx.prefix}colorinfo #{color}" embed.set_footer(text=get_text(ctx.guild, "utility", "utility.random_col").format(str(info_cmd))) await ctx.send(file=f, embed=embed) os.remove(f"db/images/{color}.png")