2024-11-23 17:36:10 +01:00
|
|
|
#!/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:
|
2024-11-23 18:15:06 +01:00
|
|
|
return f"<img src='../emoji/images/{emoji_name}' alt=':{emoji_name}:' class='emoji' />"
|
2024-11-23 17:36:10 +01:00
|
|
|
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()))
|