diff options
| author | 2018-12-27 04:05:37 +1000 | |
|---|---|---|
| committer | 2018-12-27 04:05:37 +1000 | |
| commit | c8be1f1725f497399c7c75f404f85591d7b189ed (patch) | |
| tree | fbb310f852b9833282709dc77e76aa32ef278904 | |
| parent | Merge pull request #219 from python-discord/force-bb-watch-note (diff) | |
Add charinfo command.
| -rw-r--r-- | bot/cogs/utils.py | 47 | 
1 files changed, 46 insertions, 1 deletions
| diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index b101b8816..d605cd201 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -1,8 +1,9 @@  import logging +import re +import unicodedata  from email.parser import HeaderParser  from io import StringIO -  from discord import Colour, Embed  from discord.ext.commands import AutoShardedBot, Context, command @@ -87,6 +88,50 @@ class Utils:          await ctx.message.channel.send(embed=pep_embed) +    @command() +    async def charinfo(self, ctx, *, characters: str): +        """ +        Shows you information on up to 25 unicode characters. +        """ + +        match = re.match(r"<(a?):([a-zA-Z0-9\_]+):([0-9]+)>", characters) +        if match: +            embed = Embed( +                title="Non-Character Detected", +                description=( +                    "Only unicode characters can be processed, but a custom Discord emoji " +                    "was found. Please remove it and try again." +                ) +            ) +            embed.colour = Colour.red() +            return await ctx.send(embed=embed) + +        if len(characters) > 25: +            embed = Embed(title=f"Too many characters ({len(characters)}/25)") +            embed.colour = Colour.red() +            return await ctx.send(embed=embed) + +        def get_info(char): +            digit = f"{ord(char):x}" +            if len(digit) <= 4: +                u_code = f"\\u{digit:>04}" +            else: +                u_code = f"\\U{digit:>08}" +            url = f"https://www.compart.com/en/unicode/U+{digit:>04}" +            name = f"[{unicodedata.name(char, '')}]({url})" +            info = f"`{u_code.ljust(10)}`: {name} - {char}" +            return info, u_code + +        charlist, rawlist = zip(*(get_info(c) for c in characters)) + +        embed = Embed(description="\n".join(charlist)) +        embed.set_author(name="Character Info") + +        if len(characters) > 1: +            embed.add_field(name='Raw', value=f"`{''.join(rawlist)}`", inline=False) + +        await ctx.send(embed=embed) +  def setup(bot):      bot.add_cog(Utils(bot)) | 
