创建更多喵的响应
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
from nonebot import on_message
|
from nonebot import on_message
|
||||||
from nonebot_plugin_alconna import UniMessage
|
from nonebot.internal.adapter import Event
|
||||||
|
from nonebot_plugin_alconna import UniMessage, UniMsg, Text
|
||||||
|
|
||||||
from konabot.common.nb.match_keyword import match_keyword
|
from konabot.common.nb.match_keyword import match_keyword
|
||||||
|
|
||||||
@ -8,3 +9,46 @@ evt = on_message(rule=match_keyword("喵"))
|
|||||||
@evt.handle()
|
@evt.handle()
|
||||||
async def _():
|
async def _():
|
||||||
await evt.send(await UniMessage().text("喵").export())
|
await evt.send(await UniMessage().text("喵").export())
|
||||||
|
|
||||||
|
|
||||||
|
NYA_SYMBOL_MAPPING = {
|
||||||
|
"喵": "喵",
|
||||||
|
"!": "!",
|
||||||
|
"?": "!",
|
||||||
|
"!": "!",
|
||||||
|
"?": "!",
|
||||||
|
",": ",",
|
||||||
|
",": ",",
|
||||||
|
".": ".",
|
||||||
|
"。": "。",
|
||||||
|
"…": "…",
|
||||||
|
"~": "~",
|
||||||
|
"~": "~",
|
||||||
|
" ": " ",
|
||||||
|
"\n": "\n",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 any(((char not in NYA_SYMBOL_MAPPING) for char in text)):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if len(text) <= 1:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
evt = on_message(rule=has_nya)
|
||||||
|
|
||||||
|
@evt.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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user