From 78fd69de326d97733017ddbcf4935d27c3b0e470 Mon Sep 17 00:00:00 2001 From: Sophie Tauchert Date: Sun, 8 Jan 2023 19:23:53 +0100 Subject: [PATCH] Allow emoji aliases --- ntfy/bot.py | 5 ++++- ntfy/emoji.py | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ntfy/bot.py b/ntfy/bot.py index 40b392f..8d7e7eb 100644 --- a/ntfy/bot.py +++ b/ntfy/bot.py @@ -14,7 +14,7 @@ from mautrix.util.formatter import parse_html from .config import Config from .db import DB, Topic, upgrade_table -from .emoji import parse_tags, WHITE_CHECK_MARK +from .emoji import EMOJI_FALLBACK, WHITE_CHECK_MARK, parse_tags class NtfyBot(Plugin): @@ -26,6 +26,9 @@ class NtfyBot(Plugin): await super().start() self.config.load_and_update() self.db = DB(self.database, self.log) + if EMOJI_FALLBACK: + self.log.warn( + "Please install the `emoji` package for full emoji support") await self.resubscribe() async def stop(self) -> None: diff --git a/ntfy/emoji.py b/ntfy/emoji.py index 5850474..f938abe 100644 --- a/ntfy/emoji.py +++ b/ntfy/emoji.py @@ -5,6 +5,7 @@ from mautrix.util.logging import TraceLogger try: import emoji + EMOJI_FALLBACK = False except ImportError: # basic list of supported emoji, based on https://docs.ntfy.sh/publish/#tags-emojis emoji_dict = { @@ -26,20 +27,21 @@ except ImportError: "white_check_mark": "✅", } emoji = SimpleNamespace() - emoji.emojize = lambda e: emoji_dict.get(e[1:-1], e) + emoji.emojize = lambda e, **kwargs: emoji_dict.get(e[1:-1], e) emoji.is_emoji = lambda e: e in emoji_dict.values() + EMOJI_FALLBACK = True -WHITE_CHECK_MARK = emoji.emojize(":white_check_mark:") +WHITE_CHECK_MARK = emoji.emojize(":white_check_mark:", language="alias") def parse_tags(log: TraceLogger, tags: List[str]) -> Tuple[List[str], List[str]]: - if emoji is None: + if EMOJI_FALLBACK: log.warn("Please install the `emoji` package for full emoji support") emojis = [] non_emoji_tags = [] for tag in tags: - emojized = emoji.emojize(f":{tag}:") + emojized = emoji.emojize(f":{tag}:", language="alias") if emoji.is_emoji(emojized): emojis.append(emojized) else: