How to use the demoji._EMOJI_PAT.pattern function in demoji

To help you get started, weโ€™ve selected a few demoji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DiscordWebsite / discord_logview / django_logs / formatter.py View on Github external
encoded = base64.b64encode(m.group(2).encode()).decode()
        return '\x1AI' + encoded + '\x1AI'

    # Encode inline codeblocks (`text` or ``text``)
    content = re.sub(r'(``?)([^`]+)\1', encode_inline_codeblock, content)

    def encode_mentions(m):
        encoded = base64.b64encode(m.group(1).encode()).decode()
        return '\x1AD' + encoded + '\x1AD'

    # Encode mentions
    content = re.sub(r'((@everyone)|(@here)|(<@!?(\d+)>)|(<@((.{2,32}?)#\d{4}) \((\d+)\)>)|'
                     r'(@((.{2,32}?)#\d{4}))|(<#\d+>)|(<#(.{1,100}?)>)|(<@&(\d+)>)|'
                     r'(<@&(.{1,100}?)>))', encode_mentions, content)

    jumbo_pat = fr'<(:.*?:)(\d*)>|<(a:.*?:)(\d*)>|{demoji._EMOJI_PAT.pattern}'
    jumbo = (not re.sub(r'(\s)', '', re.sub(jumbo_pat, '', content))) and (len(re.findall(jumbo_pat, content)) < 28)

    # Custom emojis (<:name:id>)
    _emoji_class = 'emoji emoji--large' if jumbo else 'emoji'
    content = re.sub(r'&lt;(:.*?:)(\d*)&gt;', fr'<img alt="\1" src="'
                                              fr'https://cdn.discordapp.com/emojis/\2.png" title="\1" class="{_emoji_class}">', content)

    # Custom animated emojis ()
    _emoji_class_animated = 'emoji emoji--large' if jumbo else 'emoji'
    content = re.sub(r'&lt;(a:.*?:)(\d*)&gt;', fr'<img alt="\1" src="'
                                               fr'https://cdn.discordapp.com/emojis/\2.gif" title="\1" class="{_emoji_class_animated}">', content)

    def process_emojis(m):
        if m.group(2) in EMOJI_LIST:
            emoji = EMOJI_LIST[m.group(2)]
            return emoji