Skip to content

feat: 优化 seglist 段处理,支持回复引用内容的文本合并#72

Open
minecraft1024a wants to merge 1 commit into
devfrom
fix/some-message-fix
Open

feat: 优化 seglist 段处理,支持回复引用内容的文本合并#72
minecraft1024a wants to merge 1 commit into
devfrom
fix/some-message-fix

Conversation

@minecraft1024a

@minecraft1024a minecraft1024a commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Improve handling of segmented reply content and adjust reply mention behavior based on group vs private chats.

New Features:

  • Support identifying seglist segments that represent reply-quoted content and merge only their text and mention parts, excluding media.
  • Control whether reply handling adds mention information based on whether the message is in a group or private context.

@sourcery-ai

sourcery-ai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR refines seglist handling to treat reply-quoted content specially by only merging text/mentions (not media), and updates the OneBot→Napcat adapter to pass a group/private context flag so reply handling can skip @-mentions in private chats while propagating it through recursive segment processing.

Sequence diagram for reply handling with group/private context

sequenceDiagram
    participant SendHandler
    participant send_normal_message
    participant handle_seg_recursive
    participant process_message_by_type
    participant handle_reply_message

    SendHandler->>send_normal_message: send_normal_message envelope
    send_normal_message->>send_normal_message: is_group = bool group_info.group_id
    send_normal_message->>handle_seg_recursive: handle_seg_recursive seg_data user_info is_group
    handle_seg_recursive->>process_message_by_type: process_message_by_type seg payload user_info is_group
    process_message_by_type->>handle_reply_message: handle_reply_message message_id user_info is_group
    alt [not is_group]
        handle_reply_message-->>process_message_by_type: return reply_seg without at
    else [is_group]
        handle_reply_message->>handle_reply_message: check enable_reply_at
        handle_reply_message-->>process_message_by_type: return reply payload with at when enabled
    end
    process_message_by_type-->>handle_seg_recursive: new_payload
    handle_seg_recursive-->>send_normal_message: processed_message
    send_normal_message-->>SendHandler: complete sending
Loading

File-Level Changes

Change Details Files
Special-case seglist parsing for reply-quoted content so only text and mentions are merged, avoiding media being treated as part of the current message.
  • Extend _handle_seglist to detect reply content based on the first text segment starting with "[回复<" or "「回复:"
  • When seglist is identified as reply content, manually merge only text_parts and at_users into the parent result and propagate reply_to if not already set
  • Fallback to the previous result.merge(inner) behavior when the seglist is not reply content
  • Update the function docstring to document the new reply-content-specific behavior
src/core/transport/message_receive/converter.py
Propagate a group/private context flag through the OneBot adapter send pipeline and use it to disable reply @-mentions in private chats.
  • Determine is_group in send_normal_message from group_info and pass it into handle_seg_recursive
  • Extend handle_seg_recursive and process_message_by_type signatures to accept and forward an is_group keyword-only flag for all segment processing, including nested seglists
  • Extend handle_reply_message to accept is_group and early-return a simple reply segment without @-mention behavior when is_group is False
  • Ensure calls to handle_reply_message and recursive seg processing consistently pass the is_group flag
plugins/onebot_adapter/src/handlers/to_napcat/send_handler.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@minecraft1024a minecraft1024a changed the base branch from main to dev June 27, 2026 08:10

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The detection of reply content in _handle_seglist based on string prefixes like "[回复<" and "「回复:" is quite brittle; consider centralizing this logic into a helper with clearer rules (e.g., configurable prefixes or a more structured flag) so it’s easier to maintain and less locale-dependent.
  • In handle_reply_message, logging "私聊消息,跳过引用艾特" at info level may be noisy for normal private message traffic; consider downgrading this to debug so it doesn’t clutter logs in common paths.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The detection of reply content in `_handle_seglist` based on string prefixes like `"[回复<"` and `"「回复:"` is quite brittle; consider centralizing this logic into a helper with clearer rules (e.g., configurable prefixes or a more structured flag) so it’s easier to maintain and less locale-dependent.
- In `handle_reply_message`, logging `"私聊消息,跳过引用艾特"` at info level may be noisy for normal private message traffic; consider downgrading this to debug so it doesn’t clutter logs in common paths.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant