mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 04:06:28 +08:00
Add "switch" builtin command
This commit is contained in:
parent
0751f05d6c
commit
6491f274fb
@ -26,17 +26,18 @@ async def handle_message(bot: NoneBot, ctx: Context_T) -> None:
|
|||||||
if coros:
|
if coros:
|
||||||
await asyncio.wait(coros)
|
await asyncio.wait(coros)
|
||||||
|
|
||||||
if ctx['message_type'] != 'private':
|
if 'to_me' not in ctx:
|
||||||
# group or discuss
|
if ctx['message_type'] != 'private':
|
||||||
ctx['to_me'] = False
|
# group or discuss
|
||||||
first_message_seg = ctx['message'][0]
|
ctx['to_me'] = False
|
||||||
if first_message_seg == MessageSegment.at(ctx['self_id']):
|
first_message_seg = ctx['message'][0]
|
||||||
|
if first_message_seg == MessageSegment.at(ctx['self_id']):
|
||||||
|
ctx['to_me'] = True
|
||||||
|
del ctx['message'][0]
|
||||||
|
if not ctx['message']:
|
||||||
|
ctx['message'].append(MessageSegment.text(''))
|
||||||
|
else:
|
||||||
ctx['to_me'] = True
|
ctx['to_me'] = True
|
||||||
del ctx['message'][0]
|
|
||||||
if not ctx['message']:
|
|
||||||
ctx['message'].append(MessageSegment.text(''))
|
|
||||||
else:
|
|
||||||
ctx['to_me'] = True
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
from none import on_command, CommandSession, permission as perm
|
from none import on_command, CommandSession, permission as perm
|
||||||
from none.message import unescape
|
from none.command import kill_current_session
|
||||||
|
from none.message import unescape, Message, handle_message
|
||||||
|
|
||||||
|
|
||||||
@on_command('echo')
|
@on_command('echo')
|
||||||
@ -11,3 +14,15 @@ async def echo(session: CommandSession):
|
|||||||
async def _(session: CommandSession):
|
async def _(session: CommandSession):
|
||||||
await session.send(
|
await session.send(
|
||||||
unescape(session.get_optional('message') or session.current_arg))
|
unescape(session.get_optional('message') or session.current_arg))
|
||||||
|
|
||||||
|
|
||||||
|
@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))
|
||||||
|
Loading…
Reference in New Issue
Block a user