mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
Improve command experience
This commit is contained in:
parent
dc889045c8
commit
0c74fbadca
@ -263,6 +263,10 @@ def _new_command_session(bot: CQHttp,
|
||||
:param ctx: message context
|
||||
:return: CommandSession object or None
|
||||
"""
|
||||
if not ctx['to_me']:
|
||||
# TODO: 支持不需要 at 的命令
|
||||
return None
|
||||
|
||||
msg_text = str(ctx['message']).lstrip()
|
||||
|
||||
for start in bot.config.COMMAND_START:
|
||||
|
@ -5,22 +5,31 @@ from aiocqhttp.message import MessageSegment
|
||||
|
||||
from .command import handle_command
|
||||
from .log import logger
|
||||
from .helpers import send
|
||||
|
||||
|
||||
async def handle_message(bot: CQHttp, ctx: Dict[str, Any]) -> None:
|
||||
# TODO: 支持让插件自己选择是否响应没有 at 的消息
|
||||
if ctx['message_type'] != 'private':
|
||||
# group or discuss
|
||||
first_message_seg = ctx['message'][0]
|
||||
if first_message_seg != MessageSegment.at(ctx['self_id']):
|
||||
return
|
||||
del ctx['message'][0]
|
||||
ctx['to_me'] = False
|
||||
indexes_to_remove = []
|
||||
for i, seg in enumerate(ctx['message']):
|
||||
if seg == MessageSegment.at(ctx['self_id']):
|
||||
ctx['to_me'] = True
|
||||
indexes_to_remove.append(i)
|
||||
for i in reversed(indexes_to_remove):
|
||||
del ctx['message'][i]
|
||||
if not ctx['message']:
|
||||
ctx['message'].append(MessageSegment.text(''))
|
||||
else:
|
||||
ctx['to_me'] = True
|
||||
|
||||
handled = await handle_command(bot, ctx)
|
||||
if handled:
|
||||
logger.debug('Message is handled as a command')
|
||||
return
|
||||
else:
|
||||
await bot.send(ctx, '你在说什么我看不懂诶')
|
||||
elif ctx['to_me']:
|
||||
await send(bot, ctx, '你在说什么我看不懂诶')
|
||||
|
||||
# TODO: NLP
|
||||
|
Loading…
Reference in New Issue
Block a user