Repository navigation
docs: document register_custom_filter in listen-message-event guide - #10643
AraragiEro wants to merge 2 commits into
Conversation
The guide only listed the built-in filters and event hooks, so there was no documented way to write a custom HandlerFilter. Add a Custom Filters section covering the filter class, the synchronous filter(event, cfg) contract, attaching to a command / command group / sub-command (including the decorator order requirement), combining with & and |, and the runtime behavior (silent skip, exception handling, command-tree filtering). Also cross-link it from Multiple Filters and mention custom filters in the event-hook tip.
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/en/dev/star/guides/listen-message-event.md" line_range="291" />
<code_context>
+
+#### Attaching to a Command Group
+
+When decorated on a `command_group`, every sub-command in the group is constrained:
+
+```python
</code_context>
<issue_to_address>
**Group restrictions do not apply**
When the group filter rejects a message matching one of its subcommands, the waking check skips the group handler but evaluates the matching subcommand independently; its `CommandFilter` does not check the group filter, so the subcommand can still run despite the guide promising a group-wide restriction.
Update the guide to clarify that a group-level custom filter constrains only the group handler, not its subcommands.
Also at `docs/zh/dev/star/guides/listen-message-event.md:291`, `docs/zh/dev/star/guides/listen-message-event.md:331`, `docs/en/dev/star/guides/listen-message-event.md:331`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: docs/en/dev/star/guides/listen-message-event.md:291
…ommands A custom filter decorated on a command_group only reaches CommandGroupFilter.custom_filter_list, which is consulted by the group handler. Sub-command handlers are evaluated independently and their CommandFilter never checks the parent group filter, so the group-level filter does not block them. Document the actual behavior, add a warning, and show that every sub-command needs its own custom_filter. Also correct the command-tree note: sub-command filters hide blocked entries, while a group-level filter blocks the group handler itself and no tree is rendered.
|
Good catch — confirmed and fixed in The review is correct: a filter decorated on a Verified with a minimal probe against the filter classes on current
Docs updated:
Separately: if the current behavior is not intended, the framework could let a sub-command's |
What
Adds a Custom Filters section to the plugin guide (
docs/zhanddocs/en→dev/star/guides/listen-message-event.md) documentingfilter.custom_filter/CustomFilter.Why
register_custom_filteris implemented inastrbot/core/star/register/star_handler.pyand exposed throughastrbot.api.event.filter, but the guide only lists the built-in filters (event_message_type,platform_adapter_type,permission_type) and the event hooks. There is currently no documented way for plugin authors to write their ownHandlerFilter.Contents
filter.CustomFilter, implement the synchronousfilter(event, cfg) -> bool, keepraise_errorwhen overriding__init__.custom_filtermust be placed abovecommand).&/|.Falseresult skips the handler silently, exceptions are caught by the framework and reported asPlugin <name>: <error>, and group/sub-command filters also hide blocked entries from the command tree.@filter.custom_filteradded to the event-hook incompatibility tip.Notes
Summary by Sourcery
Document how plugin authors can define and use custom filters in the listen-message-event guides.
Enhancements:
Documentation:
filter.custom_filterandCustomFilter, including command, group, and sub-command usage plus event-hook compatibility guidance.