From 9d3f71eb1f827d57c0fb925e83122f3f00ac5272 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Thu, 17 Dec 2020 01:26:39 +0100 Subject: [PATCH] Add command that shows how many (& which) characters can be used for react --- cogs/reactword.py | 19 +++++++++++++++++++ files/help.json | 1 + functions/reactWord.py | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/cogs/reactword.py b/cogs/reactword.py index d56c639..7c879b1 100644 --- a/cogs/reactword.py +++ b/cogs/reactword.py @@ -51,6 +51,25 @@ class ReactWord(commands.Cog): for reac in arr: await message.add_reaction(reac) + @commands.command(name="Character", aliases=["Char"], usage="[Karakter]") + @help.Category(category=Category.Other) + async def char(self, ctx, char: str = None): + # Nothing passed + if char is None: + return await ctx.send("Controleer je argumenten") + + char = char.lower() + + # Not 1 char passed + if len(char) != 1 or char not in reactWord.allowedCharacters(): + return await ctx.send("Dit is geen geldig karakter.") + + var = reactWord.getAllVariants(char) + + return await ctx.send("**Karakter**: {}\nOpties (**{}**): {}".format( + char, len(var), " ".join(var) + )) + def setup(client): client.add_cog(ReactWord(client)) diff --git a/files/help.json b/files/help.json index 0582eb4..09a7e78 100644 --- a/files/help.json +++ b/files/help.json @@ -25,6 +25,7 @@ "bitcoin sell": "Verkoop [Aantal] Bitcoins.", "buy": "Koop [Aantal] van [Item id] uit de Store.\nIndien je geen aantal opgeeft, is dit standaard 1.", "changelog": "Stuurt links naar de Didier Changelogs.", + "character": "Toont een lijst van opties van emoji's die Didier React kan gebruiken voor [Karakter], zodat je kan zien hoeveel (en welke) karakters gebruikt kunnen worden.", "clap": "Zet \"Tekst\" om naar :clap: \uD83C\uDDF9 :clap: \uD83C\uDDEA :clap: \uD83C\uDDF0 :clap: \uD83C\uDDF8 :clap: \uD83C\uDDF9 :clap:", "coinflip": "Gooi een muntje, indien je Didier Dinks inzet kan je je inzet verdubbelen (of verliezen).", "config": "Past constanten in het config bestand aan.", diff --git a/functions/reactWord.py b/functions/reactWord.py index 51f982a..b0060e6 100644 --- a/functions/reactWord.py +++ b/functions/reactWord.py @@ -259,4 +259,38 @@ def getUnicodeDict(): "asterisk": "*️⃣" } - return unidic \ No newline at end of file + return unidic + + +# Returns a list of all emoji's that exist for a char +def getAllVariants(char: str): + variants = [] + + # Letter + reg_ind = "regional_indicator_{}".format(char) + if reg_ind in getUnicodeDict(): + variants.append(reg_ind) + + # Number + elif char in getNumbers(): + variants.append(getNumbers()[char]) + + # Special Character + elif char in getSpecialCharacters(): + variants.append(getSpecialCharacters()[char]) + + # Get all doubles + if char in getDoubles(): + for letter in getDoubles()[char]: + variants.append(letter) + + # Remove doubles that might have slipped in + # Use a list here to keep the order! + uniques = [] + + for var in variants: + rep = ":" + var + ":" + if rep not in uniques: + uniques.append(rep) + + return uniques