2020-10-04 18:10:01 +08:00
|
|
|
from functools import reduce
|
|
|
|
|
2020-08-29 21:59:36 +08:00
|
|
|
from nonebot.rule import to_me
|
|
|
|
from nonebot.plugin import on_command
|
2020-10-04 18:10:01 +08:00
|
|
|
from nonebot.permission import SUPERUSER
|
2021-11-22 23:21:26 +08:00
|
|
|
from nonebot.adapters.cqhttp import (
|
|
|
|
Message,
|
|
|
|
MessageEvent,
|
|
|
|
MessageSegment,
|
|
|
|
unescape,
|
|
|
|
)
|
2020-08-29 21:59:36 +08:00
|
|
|
|
2020-10-04 18:10:01 +08:00
|
|
|
say = on_command("say", to_me(), permission=SUPERUSER)
|
2020-08-29 21:59:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
@say.handle()
|
2021-11-16 18:30:16 +08:00
|
|
|
async def say_unescape(event: MessageEvent):
|
2020-10-04 18:10:01 +08:00
|
|
|
def _unescape(message: Message, segment: MessageSegment):
|
2020-12-10 02:13:25 +08:00
|
|
|
if segment.is_text():
|
2020-12-22 20:11:48 +08:00
|
|
|
return message.append(unescape(str(segment)))
|
2020-10-04 18:10:01 +08:00
|
|
|
return message.append(segment)
|
|
|
|
|
2020-12-22 20:11:48 +08:00
|
|
|
message = reduce(_unescape, event.get_message(), Message()) # type: ignore
|
2021-11-16 18:30:16 +08:00
|
|
|
await say.send(message=message)
|
2020-10-04 18:10:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
echo = on_command("echo", to_me())
|
|
|
|
|
|
|
|
|
|
|
|
@echo.handle()
|
2021-11-16 18:30:16 +08:00
|
|
|
async def echo_escape(event: MessageEvent):
|
2021-11-21 16:12:36 +08:00
|
|
|
await echo.send(message=event.get_message())
|