nonebot2/nonebot/plugins/base.py

36 lines
1.1 KiB
Python
Raw Normal View History

from functools import reduce
from nonebot.rule import to_me
2020-12-06 02:30:19 +08:00
from nonebot.typing import State
from nonebot.plugin import on_command
from nonebot.permission import SUPERUSER
2020-12-06 02:30:19 +08:00
from nonebot.adapters import BaseBot as Bot, BaseEvent as Event, BaseMessageSegment as MessageSegment
say = on_command("say", to_me(), permission=SUPERUSER)
@say.handle()
2020-12-06 02:30:19 +08:00
async def say_unescape(bot: Bot, event: Event, state: State):
Message = event.message.__class__
def _unescape(message: Message, segment: MessageSegment):
if segment.type == "text":
return message.append(str(segment))
return message.append(segment)
message = reduce(_unescape, event.message, Message()) # type: ignore
await bot.send(message=message, event=event)
echo = on_command("echo", to_me())
@echo.handle()
2020-12-06 02:30:19 +08:00
async def echo_escape(bot: Bot, event: Event, state: State):
2020-11-07 12:36:47 +08:00
# Message = event.message.__class__
# MessageSegment = event.message[0].__class__
2020-11-07 12:36:47 +08:00
# message = Message().append( # type: ignore
# MessageSegment.text(str(event.message)))
await bot.send(message=event.message, event=event)