nonebot2/none/plugins/base.py

29 lines
824 B
Python
Raw Normal View History

2018-12-22 20:21:31 +08:00
import asyncio
2018-07-01 11:01:24 +08:00
from none import on_command, CommandSession, permission as perm
2018-12-22 20:21:31 +08:00
from none.command import kill_current_session
from none.message import unescape, Message, handle_message
2018-06-15 15:00:58 +08:00
2018-07-06 19:07:02 +08:00
@on_command('echo')
2018-06-27 22:05:12 +08:00
async def echo(session: CommandSession):
2018-07-01 17:51:01 +08:00
await session.send(session.get_optional('message') or session.current_arg)
2018-06-15 06:58:24 +08:00
2018-07-06 19:07:02 +08:00
@on_command('say', permission=perm.SUPERUSER)
2018-06-27 22:05:12 +08:00
async def _(session: CommandSession):
2018-06-30 21:00:41 +08:00
await session.send(
2018-07-01 17:51:01 +08:00
unescape(session.get_optional('message') or session.current_arg))
2018-12-22 20:21:31 +08:00
@on_command('switch', privileged=True)
async def _(session: CommandSession):
kill_current_session(session.bot, session.ctx)
msg = Message(session.current_arg)
await session.send(msg)
ctx = session.ctx.copy()
ctx['message'] = msg
asyncio.ensure_future(handle_message(session.bot, ctx))