From af952a2e2f6f287187cd0339c2a2f023fc9470c7 Mon Sep 17 00:00:00 2001 From: Sophie Tauchert Date: Sun, 8 Jan 2023 18:09:04 +0100 Subject: [PATCH] Add some fallback emoji support without the emoji package --- ntfy/emoji.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/ntfy/emoji.py b/ntfy/emoji.py index 176036d..5850474 100644 --- a/ntfy/emoji.py +++ b/ntfy/emoji.py @@ -1,19 +1,40 @@ +from types import SimpleNamespace from typing import List, Tuple from mautrix.util.logging import TraceLogger try: import emoji - WHITE_CHECK_MARK = emoji.emojize(":white_check_mark:") except ImportError: - emoji = None - WHITE_CHECK_MARK = "✅" + # basic list of supported emoji, based on https://docs.ntfy.sh/publish/#tags-emojis + emoji_dict = { + "+1": "👍", + "-1": "👎️", + "facepalm": "🤦", + "partying_face": "🥳", + "warning": "⚠️", + "no_entry": "⛔", + "tada": "🎉", + "rotating_light": "🚨", + "no_entry_sign": "🚫", + "heavy_check_mark": "✔️", + "triangular_flag_on_post": "🚩", + "cd": "💿", + "loudspeaker": "📢", + "skull": "💀", + "computer": "💻", + "white_check_mark": "✅", + } + emoji = SimpleNamespace() + emoji.emojize = lambda e: emoji_dict.get(e[1:-1], e) + emoji.is_emoji = lambda e: e in emoji_dict.values() + +WHITE_CHECK_MARK = emoji.emojize(":white_check_mark:") def parse_tags(log: TraceLogger, tags: List[str]) -> Tuple[List[str], List[str]]: if emoji is None: - log.warn("Please install the `emoji` package for emoji support") - return ([], tags) + log.warn("Please install the `emoji` package for full emoji support") emojis = [] non_emoji_tags = []