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 .config import Config
|
||||||
from .db import DB, Topic, upgrade_table
|
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):
|
class NtfyBot(Plugin):
|
||||||
|
@ -26,6 +26,9 @@ class NtfyBot(Plugin):
|
||||||
await super().start()
|
await super().start()
|
||||||
self.config.load_and_update()
|
self.config.load_and_update()
|
||||||
self.db = DB(self.database, self.log)
|
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()
|
await self.resubscribe()
|
||||||
|
|
||||||
async def stop(self) -> None:
|
async def stop(self) -> None:
|
||||||
|
|
|
@ -5,6 +5,7 @@ from mautrix.util.logging import TraceLogger
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import emoji
|
import emoji
|
||||||
|
EMOJI_FALLBACK = False
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# basic list of supported emoji, based on https://docs.ntfy.sh/publish/#tags-emojis
|
# basic list of supported emoji, based on https://docs.ntfy.sh/publish/#tags-emojis
|
||||||
emoji_dict = {
|
emoji_dict = {
|
||||||
|
@ -26,20 +27,21 @@ except ImportError:
|
||||||
"white_check_mark": "✅",
|
"white_check_mark": "✅",
|
||||||
}
|
}
|
||||||
emoji = SimpleNamespace()
|
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.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]]:
|
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")
|
log.warn("Please install the `emoji` package for full emoji support")
|
||||||
emojis = []
|
emojis = []
|
||||||
non_emoji_tags = []
|
non_emoji_tags = []
|
||||||
|
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
emojized = emoji.emojize(f":{tag}:")
|
emojized = emoji.emojize(f":{tag}:", language="alias")
|
||||||
if emoji.is_emoji(emojized):
|
if emoji.is_emoji(emojized):
|
||||||
emojis.append(emojized)
|
emojis.append(emojized)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue