Skip to content

Commit

Permalink
🚸 improve reply check
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Jul 6, 2024
1 parent d41782b commit d8e3311
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
23 changes: 14 additions & 9 deletions nonebot/adapters/onebot/v11/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,25 @@ async def _check_reply(bot: "Bot", event: MessageEvent) -> None:
except Exception as e:
log("WARNING", f"Error when getting message reply info: {repr(e)}")
return
# ensure string comparation
if str(event.reply.sender.user_id) == str(event.self_id):
event.to_me = True
del event.message[index]
if (
len(event.message) > index
and event.message[index].type == "at"
and event.message[index].data.get("qq") == str(event.reply.sender.user_id)
):

if event.reply.sender.user_id is not None:
# ensure string comparation
if str(event.reply.sender.user_id) == str(event.self_id):
event.to_me = True
del event.message[index]

if (
len(event.message) > index
and event.message[index].type == "at"
and event.message[index].data.get("qq") == str(event.reply.sender.user_id)
):
del event.message[index]

if len(event.message) > index and event.message[index].type == "text":
event.message[index].data["text"] = event.message[index].data["text"].lstrip()
if not event.message[index].data["text"]:
del event.message[index]

if not event.message:
event.message.append(MessageSegment.text(""))

Expand Down
7 changes: 3 additions & 4 deletions nonebot/adapters/onebot/v12/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,27 @@ def _check_reply(bot: "Bot", event: MessageEvent) -> None:

try:
event.reply = type_validate_python(Reply, msg_seg.data)
# event.reply = Reply.parse_obj(
# await bot.get_msg(message_id=msg_seg.data["id"])
# )
except Exception as e:
log("WARNING", f"Error when getting message reply info: {repr(e)}", e)
return

# ensure string comparation
if str(event.reply.user_id) == str(event.self.user_id):
event.to_me = True

del event.message[index]

if (
len(event.message) > index
and event.message[index].type == "mention"
and event.message[index].data.get("user_id") == str(event.reply.user_id)
):
del event.message[index]

if len(event.message) > index and event.message[index].type == "text":
event.message[index].data["text"] = event.message[index].data["text"].lstrip()
if not event.message[index].data["text"]:
del event.message[index]

if not event.message:
event.message.append(MessageSegment.text(""))

Expand Down

0 comments on commit d8e3311

Please sign in to comment.