Allow emoji aliases
This commit is contained in:
parent
3f0bf11858
commit
78fd69de32
2 changed files with 10 additions and 5 deletions
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue