fix: accept extra after-message hook args#239
Merged
EterUltimate merged 1 commit intoJul 9, 2026
Merged
Conversation
Contributor
Reviewer's GuideThis PR updates the self-learning plugin’s after-message hook to accept extra positional arguments passed by AstrBot and adds an integration test to ensure the hook’s signature remains compatible when imported via the AstrBot package path. Sequence diagram for AstrBot calling the updated after_message_sent hooksequenceDiagram
participant AstrBotCore
participant SelfLearningPlugin
AstrBotCore->>SelfLearningPlugin: on_bot_message_sent(event, extra_arg)
activate SelfLearningPlugin
SelfLearningPlugin->>SelfLearningPlugin: reset_trace_context()
SelfLearningPlugin->>SelfLearningPlugin: [store message in database]
deactivate SelfLearningPlugin
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
test_after_message_sent_hook_accepts_framework_extra_args, consider tightening the assertion to verify the position of the*argsparameter (e.g., that it is the second parameter afterevent) rather than only checking that a VAR_POSITIONAL parameter exists somewhere in the signature. - In
on_bot_message_sent, the extra positional args are intentionally unused; adding a brief inline comment explaining that they are accepted solely for AstrBot hook compatibility would help prevent future refactors from mistakenly removing them.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `test_after_message_sent_hook_accepts_framework_extra_args`, consider tightening the assertion to verify the position of the `*args` parameter (e.g., that it is the second parameter after `event`) rather than only checking that a VAR_POSITIONAL parameter exists somewhere in the signature.
- In `on_bot_message_sent`, the extra positional args are intentionally unused; adding a brief inline comment explaining that they are accepted solely for AstrBot hook compatibility would help prevent future refactors from mistakenly removing them.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
after_message_senthook.Evidence
lxfight-s-Astrbot-Plugins/astrbot_plugin_livingmemoryPR [Feature] 自动清理注入到user prompt的提示 #196 / mergee2ac45d4bdb09a42def646be21cc6292a2b02736fixed the same AstrBot v4.26.5 hook dispatcher issue.after_message_sentasevent, *args, **kwargs, producingTypeError: ... takes 2 positional arguments but 3 were givenfor single-argument plugin hooks.main.pyhadSelfLearningPlugin.on_bot_message_sent(self, event)under@filter.after_message_sent().Validation
python -m pytest tests/integration/test_package_imports.py -qpython -m py_compile main.py tests\integration\test_package_imports.pygit diff --checkC:\Users\zacza\Desktop\x\AstrBot\data\plugins\astrbot_plugin_self_learning: imported plugin and calledon_bot_message_sent(event, extra_arg)successfully.Summary by Sourcery
Allow the self-learning plugin’s after-message hook to accept extra positional arguments while ensuring its signature remains compatible with AstrBot’s framework calls.
Bug Fixes:
Enhancements: