Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

🐛 修复 get_message_id 被弃用的问题并简单修缮了代码格式#32

Merged
Asankilp merged 5 commits into
LiteyukiStudio:mainfrom
Moemu:main
Aug 16, 2025
Merged

🐛 修复 get_message_id 被弃用的问题并简单修缮了代码格式#32
Asankilp merged 5 commits into
LiteyukiStudio:mainfrom
Moemu:main

Conversation

@Moemu

@Moemu Moemu commented Aug 16, 2025

Copy link
Copy Markdown
Contributor

主要更新:

好饿哦 呐呐,陪我出去玩好不好

Summary by Sourcery

Fix deprecated API usage and improve code robustness and formatting

Bug Fixes:

  • Replace deprecated UniMessage.get_message_id call with get_message_id
  • Add missing await for build_praises to correctly handle async result
  • Add guard in process_completion_to_details to handle non-ChatCompletion inputs
  • Fix debounce decorator to allow initial invocation

Enhancements:

  • Refactor on_plugin_file_change for clearer early-return logic
  • Add assertions and type annotations to improve type safety and suppress errors
  • Apply minor formatting and type-ignore adjustments across modules

@sourcery-ai

sourcery-ai Bot commented Aug 16, 2025

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR fixes the deprecated get_message_id usage and applies targeted refactoring and formatting updates across modules, including simplifying plugin reload logic, adding type guards for streaming responses, improving debounce behavior, and minor code annotations.

Sequence diagram for plugin file change and reload logic update

sequenceDiagram
    participant FileSystemEvent
    participant on_plugin_file_change
    participant get_plugin
    participant reload_plugin
    participant context
    FileSystemEvent->>on_plugin_file_change: File change event (.py)
    on_plugin_file_change->>get_plugin: Search for plugin by name
    alt Found package plugin
        on_plugin_file_change->>reload_plugin: Reload package plugin
        reload_plugin->>context: Reset all context
    else Found single-file plugin
        on_plugin_file_change->>reload_plugin: Reload single-file plugin
        reload_plugin->>context: Reset all context
    else Not found
        on_plugin_file_change->>on_plugin_file_change: Log not found
    end
Loading

Class diagram for handler and event message ID update

classDiagram
    class Handler {
        - event: Event
        - matcher: Matcher
        - message_id: str
        - target
        + __init__()
        ...
    }
    Handler : message_id uses get_message_id(event)
Loading

Class diagram for debounce decorator and CodeModifiedHandler update

classDiagram
    class CodeModifiedHandler {
        + on_modified(event: FileSystemEvent)
        + on_created(event)
    }
    class debounce {
        + decorator(func)
    }
    CodeModifiedHandler <|-- debounce
Loading

Class diagram for process_completion_to_details type guard

classDiagram
    class process_completion_to_details {
        + process_completion_to_details(completion: ChatCompletion) -> str
    }
    process_completion_to_details : type guard for ChatCompletion
    process_completion_to_details : returns error string if not ChatCompletion
Loading

File-Level Changes

Change Details Files
Refactor plugin file change handler for early exits and unified flow
  • Added early return for non-.py events
  • Replaced nested if/else with continue logic in the plugin search loop
  • Introduced for-else to log when no plugin is found
nonebot_plugin_marshoai/dev.py
Add type guard and annotations in processor utilities
  • Inserted isinstance check in process_completion_to_details to handle unsupported inputs
  • Appended # type:ignore to reasoning_content operations
nonebot_plugin_marshoai/utils/processor.py
Replace deprecated message ID retrieval and update handler signatures
  • Swapped UniMessage.get_message_id for get_message_id
  • Expanded completion parameter type to include AsyncStream chunks
  • Added # type:ignore on the send call
nonebot_plugin_marshoai/handler.py
Improve debounce decorator logic and type annotations
  • Added check for None on last_call_time before timing logic
  • Annotated on_modified event parameter with FileSystemEvent
nonebot_plugin_marshoai/observer.py
Enforce spec existence and suppress loader type warnings
  • Assert that spec is not None when loading packages
  • Appended # type:ignore when executing module loader
nonebot_plugin_marshoai/models.py
Ensure asynchronous build call is awaited
  • Added await keyword before build_praises()
nonebot_plugin_marshoai/marsho.py

Possibly linked issues


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

@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 there - I've reviewed your changes - here's some feedback:

  • In on_plugin_file_change, the reload logic for package vs single-file plugins is duplicated; consider extracting the common reload+reset steps into a helper to flatten the control flow.
  • In process_completion_to_details, returning a plain string for unsupported inputs mixes error and normal flows—consider using an exception or a dedicated result type to distinguish errors cleanly.
  • The scattered # type:ignore comments indicate missing or inaccurate type definitions (e.g. delta.reasoning_content); it’d be better to update the type stubs or ChatCompletionChunk model rather than silencing the checks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In on_plugin_file_change, the reload logic for package vs single-file plugins is duplicated; consider extracting the common reload+reset steps into a helper to flatten the control flow.
- In process_completion_to_details, returning a plain string for unsupported inputs mixes error and normal flows—consider using an exception or a dedicated result type to distinguish errors cleanly.
- The scattered # type:ignore comments indicate missing or inaccurate type definitions (e.g. delta.reasoning_content); it’d be better to update the type stubs or ChatCompletionChunk model rather than silencing the checks.

## Individual Comments

### Comment 1
<location> `nonebot_plugin_marshoai/models.py:119` </location>
<code_context>
                 spec = importlib.util.spec_from_file_location(
                     package_name, os.path.join(package_path, "__init__.py")
                 )
+                assert spec, f"工具包 {package_name} 未找到"
                 package = importlib.util.module_from_spec(spec)
                 self.imported_packages[package_name] = package
</code_context>

<issue_to_address>
Using assert for runtime error handling may be inappropriate.

Assert statements can be disabled with Python optimizations, so replace with an explicit exception to guarantee error handling in all environments.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
                assert spec, f"工具包 {package_name} 未找到"
=======
                if not spec:
                    raise ImportError(f"工具包 {package_name} 未找到")
>>>>>>> REPLACE

</suggested_fix>

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.

Comment thread nonebot_plugin_marshoai/models.py Outdated
if not (plugin := get_plugin(plugin_name)):
continue

if (

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.

issue (code-quality): We've found these issues:

@@ -124,7 +125,7 @@ async def handle_single_chat(

async def handle_function_call(
self,

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.

issue (code-quality): We've found these issues:

Moemu and others added 2 commits August 16, 2025 16:54
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@Asankilp
Asankilp merged commit 6050fd1 into LiteyukiStudio:main Aug 16, 2025
6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants