Add support for Discord templates

This commit is contained in:
Nadir Chowdhury
2020-06-28 19:48:04 +01:00
committed by GitHub
parent 7a07644de3
commit 2b3c6e0d47
6 changed files with 205 additions and 2 deletions

View File

@ -451,6 +451,17 @@ def resolve_invite(invite):
return m.group(1)
return invite
def resolve_template(code):
from .template import Template # circular import
if isinstance(code, (Template, Object)):
return template.id
else:
rx = r'(?:https?\:\/\/)?discord(?:\.new|(?:app)?\.com\/template)\/(.+)'
m = re.match(rx, code)
if m:
return m.group(1)
return code
_MARKDOWN_ESCAPE_SUBREGEX = '|'.join(r'\{0}(?=([\s\S]*((?<!\{0})\{0})))'.format(c)
for c in ('*', '`', '_', '~', '|'))