nonebot2/nonebot/plugins/echo.py

30 lines
884 B
Python
Raw Normal View History

from functools import reduce
from nonebot.rule import to_me
from nonebot.plugin import on_command
from nonebot.permission import SUPERUSER
2021-09-27 00:19:30 +08:00
from nonebot.adapters.cqhttp import (Bot, Message, MessageEvent, MessageSegment,
unescape)
say = on_command("say", to_me(), permission=SUPERUSER)
@say.handle()
async def say_unescape(bot: Bot, event: MessageEvent):
def _unescape(message: Message, segment: MessageSegment):
2020-12-10 02:13:25 +08:00
if segment.is_text():
return message.append(unescape(str(segment)))
return message.append(segment)
message = reduce(_unescape, event.get_message(), Message()) # type: ignore
await bot.send(message=message, event=event)
echo = on_command("echo", to_me())
@echo.handle()
async def echo_escape(bot: Bot, event: MessageEvent):
2020-12-10 02:13:25 +08:00
await bot.send(message=event.get_message(), event=event)