31 lines
952 B
Python
31 lines
952 B
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import sys
|
||
|
import os
|
||
|
import json
|
||
|
import re
|
||
|
|
||
|
mm_server = os.environ["MM_SERVER"]
|
||
|
|
||
|
with open(sys.argv[1]) as fh:
|
||
|
custom_emoji = json.load(fh)
|
||
|
with open("./builtin_emoji.json") as fh:
|
||
|
builtin_emoji = json.load(fh)
|
||
|
|
||
|
def translate_emoji(match_obj):
|
||
|
emoji_name = match_obj.group(1)
|
||
|
for emoji in builtin_emoji:
|
||
|
if emoji_name in emoji["aliases"]:
|
||
|
return "".join(
|
||
|
chr(int(unicode_codepoint, 16))
|
||
|
for unicode_codepoint in emoji["filename"].split("-")
|
||
|
)
|
||
|
for emoji in custom_emoji:
|
||
|
if emoji["name"] == emoji_name:
|
||
|
return f"<img src='/emoji_proxy/{mm_server}/{emoji['id']}' alt=':{emoji_name}:' class='emoji' />"
|
||
|
return f":{emoji_name}:"
|
||
|
|
||
|
# From https://mattermost.example.org/<team_name>/emoji/add:
|
||
|
# Specify an emoji name that's up to 64 characters. It can contain lowercase letters, numbers, and the symbols '-', '+' and '_'.
|
||
|
print(re.sub(r'(?!<[^>]*):([a-z0-9_+-]{1,64}):', translate_emoji, sys.stdin.read()))
|