mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 09:05:04 +08:00
33 lines
815 B
Python
33 lines
815 B
Python
from functools import reduce
|
|
|
|
from nonebot.rule import to_me
|
|
from nonebot.plugin import on_command
|
|
from nonebot.permission import SUPERUSER
|
|
from nonebot.adapters.cqhttp import (
|
|
Message,
|
|
MessageEvent,
|
|
MessageSegment,
|
|
unescape,
|
|
)
|
|
|
|
say = on_command("say", to_me(), permission=SUPERUSER)
|
|
|
|
|
|
@say.handle()
|
|
async def say_unescape(event: MessageEvent):
|
|
def _unescape(message: Message, segment: MessageSegment):
|
|
if segment.is_text():
|
|
return message.append(unescape(str(segment)))
|
|
return message.append(segment)
|
|
|
|
message = reduce(_unescape, event.get_message(), Message()) # type: ignore
|
|
await say.send(message=message)
|
|
|
|
|
|
echo = on_command("echo", to_me())
|
|
|
|
|
|
@echo.handle()
|
|
async def echo_escape(event: MessageEvent):
|
|
await echo.send(message=event.get_message())
|