From 47aede8f6795f53fcc44e9b9c90dba92b44e2eba Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Thu, 19 Nov 2020 13:57:49 +0800 Subject: [PATCH] :bug: fix index error when check to me --- nonebot/adapters/cqhttp/__init__.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nonebot/adapters/cqhttp/__init__.py b/nonebot/adapters/cqhttp/__init__.py index f6e91681..546fe862 100644 --- a/nonebot/adapters/cqhttp/__init__.py +++ b/nonebot/adapters/cqhttp/__init__.py @@ -112,14 +112,15 @@ async def _check_reply(bot: "Bot", event: "Event"): return msg_seg = event.message[index] event.reply = await bot.get_msg(message_id=msg_seg.data["id"]) - if event.reply["sender"]["user_id"] == int(event.self_id): # TODO 这里一个int一个str需要修改 + # ensure string comparation + if str(event.reply["sender"]["user_id"]) == str(event.self_id): event.to_me = True del event.message[index] if not event.message: event.message.append(MessageSegment.text("")) -def _check_at_me(bot: "Bot", event: "Event"): # TODO 只有开头at机器人才会识别,其他的不管 应该删除前面两个如果存在的at以及后面正文前面的空格 +def _check_at_me(bot: "Bot", event: "Event"): """ :说明: @@ -138,23 +139,22 @@ def _check_at_me(bot: "Bot", event: "Event"): # TODO 只有开头at机器人才 else: at_me_seg = MessageSegment.at(event.self_id) - # check the first segment at 空 at - if event.message[0] == at_me_seg: # TODO 有时候不能正常判断 + # check the first segment + if event.message[0] == at_me_seg: event.to_me = True del event.message[0] - if event.message[0].type == "text": + if event.message and event.message[0].type == "text": event.message[0].data["text"] = event.message[0].data[ "text"].lstrip() if not event.message[0].data["text"]: del event.message[0] - if event.message: - if event.message[0] == at_me_seg: - del event.message[0] - if event.message[0].type == "text": - event.message[0].data["text"] = event.message[0].data[ - "text"].lstrip() - if not event.message[0].data["text"]: - del event.message[0] + if event.message and event.message[0] == at_me_seg: + del event.message[0] + if event.message and event.message[0].type == "text": + event.message[0].data["text"] = event.message[0].data[ + "text"].lstrip() + if not event.message[0].data["text"]: + del event.message[0] if not event.to_me: # check the last segment