Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'<(:.*?:)(\d*)>', 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'<(a:.*?:)(\d*)>', 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