Skip to content

fix: merge consecutive duplicate MentionUser segments in message parsing (closes #214)#218

Open
botbikamordehai2-sketch wants to merge 2 commits into
nonebot:masterfrom
botbikamordehai2-sketch:fix/issue-214-1784113177
Open

fix: merge consecutive duplicate MentionUser segments in message parsing (closes #214)#218
botbikamordehai2-sketch wants to merge 2 commits into
nonebot:masterfrom
botbikamordehai2-sketch:fix/issue-214-1784113177

Conversation

@botbikamordehai2-sketch

Copy link
Copy Markdown

What

When receiving group messages in full-message mode, the QQ platform sometimes sends two consecutive MentionUser segments with the same user_id. The first one has empty text, and the second contains the actual mention text, causing redundant entries.

Fix

Added a classmethod merge_consecutive_mentions that scans a list of MessageSegment and merges consecutive MentionUser segments with identical user_id into one, keeping the non-empty data (preferring the later segment). This can be called in the message parsing logic to clean up the message before returning it.

Closes #214

@yanyongyu

Copy link
Copy Markdown
Member

看着不太对吧,#214 里的情况是收到这样的

[MentionUser(type='mention_user', data={'user_id': '73A48B12B0D76B961B4349B5599FA43C', 'username': '69(大喇叭是宝宝', 'is_bot': False}), Text(type='text', data={'text': ' '}), MentionUser(type='mention_user', data={'user_id': '73A48B12B0D76B961B4349B5599FA43C', 'username': '69(大喇叭是宝宝', 'is_bot': False}), Text(type='text', data={'text': ' 你多少分'})]

因为回复了两遍所以有两个 at,中间有一个空格。

你的 PR 修复的又是什么情况?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

MentionUser消息结构问题

2 participants