async def rgb(self, ctx, *, rgb_value): """ Find the closest color name corresponding to the RGB value, if any. """ rgb_value_match = re.match(r'^(\d{,3})\D+(\d{,3})\D+(\d{,3})$', rgb_value) if not rgb_value_match: return await ctx.send( f'"{escape_mentions(rgb_value)}" is not a valid RGB value.') r, g, b = map(int, rgb_value_match.groups()) if not 0 <= r <= 255 or not 0 <= g <= 255 or not 0 <= b <= 255: return await ctx.send(f'`{rgb_value}` is not a valid RGB value.') hex_code = '{0:02x}{1:02x}{2:02x}'.format(r, g, b) if self.bot.version >= parse_version('3.3.0-dev0'): possibilities = { v: k for k, v in ALL_COLORS.items() if v[::2] == hex_code[::2] } else: possibilities = { v: k for k, v in ALL_COLORS.items() if v[1::2] == hex_code[::2] } closest_hex = difflib.get_close_matches(hex_code, possibilities, n=1) if not closest_hex: return await ctx.send( f'RGB values `{r}, {g}, {b}` does not have an known color name.' ) closest_hex = closest_hex[0] clean_name = re.match(r'^(?:[^:]+:)?([^:]+)$', possibilities[closest_hex]).group(1) embed = Embed( title=f'RGB {r}, {g}, {b}', description=f'Closest color name: "{clean_name.title()}".') if self.bot.version >= parse_version('3.3.0-dev0'): embed.set_thumbnail( url=f'https://placehold.it/100/{closest_hex}?text=+') else: embed.set_thumbnail( url=f'https://placehold.it/100/{closest_hex[1:]}?text=+') return await ctx.send(embed=embed)
async def rgb(self, ctx, *, rgb_value): """ Trova il tuo nome di colore più vicino corrispondente al valore RGB, se c'è uno. """ rgb_value_match = re.match(r'^(\d{,3})\D+(\d{,3})\D+(\d{,3})$', rgb_value) if not rgb_value_match: return await ctx.send( f'"{escape_mentions(rgb_value)}" non è un valore RGB valido.') r, g, b = map(int, rgb_value_match.groups()) if not 0 <= r <= 255 or not 0 <= g <= 255 or not 0 <= b <= 255: return await ctx.send(f'`{rgb_value}` non è un valore RGB valido.') hex_code = '{0:02x}{1:02x}{2:02x}'.format(r, g, b) if self.bot.version >= parse_version('3.3.0-dev0'): possibilities = { v: k for k, v in ALL_COLORS.items() if v[::2] == hex_code[::2] } else: possibilities = { v: k for k, v in ALL_COLORS.items() if v[1::2] == hex_code[::2] } closest_hex = difflib.get_close_matches(hex_code, possibilities, n=1) if not closest_hex: return await ctx.send( f'I valori RGB `{r}, {g}, {b}` non hanno un nome di colore conosciuto.' ) closest_hex = closest_hex[0] clean_name = re.match(r'^(?:[^:]+:)?([^:]+)$', possibilities[closest_hex]).group(1) embed = Embed( title=f'RGB {r}, {g}, {b}', description=f'Nome di colore più vicino: "{clean_name.title()}".') if self.bot.version >= parse_version('3.3.0-dev0'): embed.set_thumbnail( url=f'https://placehold.it/100/{closest_hex}?text=+') else: embed.set_thumbnail( url=f'https://placehold.it/100/{closest_hex[1:]}?text=+') return await ctx.send(embed=embed)
async def hex(self, ctx, *, hex_code: str.lower): """ Trova il tuo nome di colore più vicino corrispondente al codice hex. """ hex_code_match = re.match(r'^#?([a-f0-9]{6}|[a-f0-9]{3})$', hex_code) if hex_code_match is None: return await ctx.send( f'"{escape_mentions(hex_code)}" non è un codice hex valido.') hex_code = hex_code_match.group(1) if len(hex_code) == 3: hex_code = ''.join(s for s in hex_code for _ in range(2)) if self.bot.version >= parse_version('3.3.0-dev0'): possibilities = { v: k for k, v in ALL_COLORS.items() if v[::2] == hex_code[::2] } else: possibilities = { v: k for k, v in ALL_COLORS.items() if v[1::2] == hex_code[::2] } closest_hex = difflib.get_close_matches(hex_code, possibilities, n=1) if not closest_hex: return await ctx.send( f'Il codice hex `#{hex_code}` non ha un nome di colore conosciuto.' ) closest_hex = closest_hex[0] clean_name = re.match(r'^(?:[^:]+:)?([^:]+)$', possibilities[closest_hex]).group(1) embed = Embed( title=f'#{hex_code}', description=f'Nome di colore più vicino: "{clean_name.title()}".') if self.bot.version >= parse_version('3.3.0-dev0'): embed.set_thumbnail( url=f'https://placehold.it/100/{closest_hex}?text=+') else: embed.set_thumbnail( url=f'https://placehold.it/100/{closest_hex[1:]}?text=+') return await ctx.send(embed=embed)
async def hex(self, ctx, *, hex_code: str.lower): """ Find the closest color name corresponding to the hex code, if any. """ hex_code_match = re.match(r'^#?([a-f0-9]{6}|[a-f0-9]{3})$', hex_code) if hex_code_match is None: return await ctx.send( f'"{escape_mentions(hex_code)}" is not a valid hex code.') hex_code = hex_code_match.group(1) if len(hex_code) == 3: hex_code = ''.join(s for s in hex_code for _ in range(2)) if self.bot.version >= parse_version('3.3.0-dev0'): possibilities = { v: k for k, v in ALL_COLORS.items() if v[::2] == hex_code[::2] } else: possibilities = { v: k for k, v in ALL_COLORS.items() if v[1::2] == hex_code[::2] } closest_hex = difflib.get_close_matches(hex_code, possibilities, n=1) if not closest_hex: return await ctx.send( f'Hex code `#{hex_code}` does not have an known color name.') closest_hex = closest_hex[0] clean_name = re.match(r'^(?:[^:]+:)?([^:]+)$', possibilities[closest_hex]).group(1) embed = Embed( title=f'#{hex_code}', description=f'Closest color name: "{clean_name.title()}".') if self.bot.version >= parse_version('3.3.0-dev0'): embed.set_thumbnail( url=f'https://placehold.it/100/{closest_hex}?text=+') else: embed.set_thumbnail( url=f'https://placehold.it/100/{closest_hex[1:]}?text=+') return await ctx.send(embed=embed)