nonebot2/nonebot/plugins/base.py

31 lines
900 B
Python
Raw Normal View History

from functools import reduce
from nonebot.rule import to_me
2020-12-17 21:09:30 +08:00
from nonebot.typing import T_State
from nonebot.plugin import on_command
from nonebot.permission import SUPERUSER
2020-12-17 21:09:30 +08:00
from nonebot.adapters import Bot, Event, Message, MessageSegment
say = on_command("say", to_me(), permission=SUPERUSER)
@say.handle()
2020-12-17 21:09:30 +08:00
async def say_unescape(bot: Bot, event: Event, state: T_State):
MessageImpl = event.get_message().__class__
def _unescape(message: Message, segment: MessageSegment):
2020-12-10 02:13:25 +08:00
if segment.is_text():
return message.append(str(segment))
return message.append(segment)
2020-12-17 21:09:30 +08:00
message = reduce(_unescape, event.get_message(), MessageImpl())
await bot.send(message=message, event=event)
echo = on_command("echo", to_me())
@echo.handle()
2020-12-17 21:09:30 +08:00
async def echo_escape(bot: Bot, event: Event, state: T_State):
2020-12-10 02:13:25 +08:00
await bot.send(message=event.get_message(), event=event)