Files
konabot/konabot/plugins/nya_echo/__init__.py

61 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from nonebot import on_message
from nonebot.internal.adapter import Event
from nonebot_plugin_alconna import UniMessage, UniMsg, Text
from konabot.common.nb.match_keyword import match_keyword
evt_nya = on_message(rule=match_keyword(""))
@evt_nya.handle()
async def _():
await evt_nya.send(await UniMessage().text("").export())
NYA_SYMBOL_MAPPING = {
"": "",
"!": "!",
"?": "!",
"": "",
"": "",
",": ",",
"": "",
".": ".",
"": "",
"": "",
"~": "~",
"": "",
" ": " ",
}
NYA_SYMBOL_KEEP = "—¹₁²₂³₃⁴₄⁵₅⁶₆⁷₇⁸₈⁹₉⁰₀\n"
NYA_SYMBOL_MAPPING.update((k, k) for k in NYA_SYMBOL_KEEP)
async def has_nya(msg: UniMsg) -> bool:
if any((not isinstance(seg, Text) for seg in msg)):
return False
text = msg.extract_plain_text()
if len(text) <= 1:
return False
if "" not in text:
return False
if any(((char not in NYA_SYMBOL_MAPPING) for char in text)):
return False
return True
evt_nya_v2 = on_message(rule=has_nya)
@evt_nya_v2.handle()
async def _(msg: UniMsg, evt: Event):
text = msg.extract_plain_text()
await UniMessage.text("".join((NYA_SYMBOL_MAPPING.get(c, "") for c in text))).send(
evt
)