-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: add missing platform adapter filter types #7738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||||||||
| class PlatformAdapterType(enum.Flag): | ||||||||||||
| AIOCQHTTP = enum.auto() | ||||||||||||
| QQOFFICIAL = enum.auto() | ||||||||||||
| QQOFFICIAL_WEBHOOK = enum.auto() | ||||||||||||
| TELEGRAM = enum.auto() | ||||||||||||
| WECOM = enum.auto() | ||||||||||||
| WECOM_AI_BOT = enum.auto() | ||||||||||||
|
|
@@ -23,29 +24,16 @@ class PlatformAdapterType(enum.Flag): | |||||||||||
| MISSKEY = enum.auto() | ||||||||||||
| LINE = enum.auto() | ||||||||||||
| MATRIX = enum.auto() | ||||||||||||
| ALL = ( | ||||||||||||
| AIOCQHTTP | ||||||||||||
| | QQOFFICIAL | ||||||||||||
| | TELEGRAM | ||||||||||||
| | WECOM | ||||||||||||
| | WECOM_AI_BOT | ||||||||||||
| | LARK | ||||||||||||
| | DINGTALK | ||||||||||||
| | DISCORD | ||||||||||||
| | SLACK | ||||||||||||
| | KOOK | ||||||||||||
| | VOCECHAT | ||||||||||||
| | WEIXIN_OFFICIAL_ACCOUNT | ||||||||||||
| | SATORI | ||||||||||||
| | MISSKEY | ||||||||||||
| | LINE | ||||||||||||
| | MATRIX | ||||||||||||
| ) | ||||||||||||
| WEIXIN_OC = enum.auto() | ||||||||||||
| MATTERMOST = enum.auto() | ||||||||||||
| WEBCHAT = enum.auto() | ||||||||||||
| ALL = enum.auto() | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| ADAPTER_NAME_2_TYPE = { | ||||||||||||
| "aiocqhttp": PlatformAdapterType.AIOCQHTTP, | ||||||||||||
| "qq_official": PlatformAdapterType.QQOFFICIAL, | ||||||||||||
| "qq_official_webhook": PlatformAdapterType.QQOFFICIAL_WEBHOOK, | ||||||||||||
| "telegram": PlatformAdapterType.TELEGRAM, | ||||||||||||
| "wecom": PlatformAdapterType.WECOM, | ||||||||||||
| "wecom_ai_bot": PlatformAdapterType.WECOM_AI_BOT, | ||||||||||||
|
|
@@ -60,6 +48,9 @@ class PlatformAdapterType(enum.Flag): | |||||||||||
| "misskey": PlatformAdapterType.MISSKEY, | ||||||||||||
| "line": PlatformAdapterType.LINE, | ||||||||||||
| "matrix": PlatformAdapterType.MATRIX, | ||||||||||||
| "weixin_oc": PlatformAdapterType.WEIXIN_OC, | ||||||||||||
| "mattermost": PlatformAdapterType.MATTERMOST, | ||||||||||||
| "webchat": PlatformAdapterType.WEBCHAT, | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+53
to
54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The string
Suggested change
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -71,6 +62,12 @@ def __init__(self, platform_adapter_type_or_str: PlatformAdapterType | str) -> N | |||||||||||
| self.platform_type = platform_adapter_type_or_str | ||||||||||||
|
|
||||||||||||
| def filter(self, event: AstrMessageEvent, cfg: AstrBotConfig) -> bool: | ||||||||||||
| if ( | ||||||||||||
| self.platform_type is not None | ||||||||||||
| and self.platform_type & PlatformAdapterType.ALL | ||||||||||||
| ): | ||||||||||||
| return True | ||||||||||||
|
Comment on lines
+65
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): The ALL-flag early return changes behavior for composite filters and may bypass future platform-specific logic. This early return means any filter whose mask includes Suggested implementation: def filter(self, event: AstrMessageEvent, cfg: AstrBotConfig) -> bool:
# If the filter is explicitly "ALL", accept any platform without restriction.
# For composite masks (e.g., ALL | QQOFFICIAL), we still run the per-platform logic below.
if self.platform_type == PlatformAdapterType.ALL:
return True
adapter_name = event.get_platform_name() if adapter_name in ADAPTER_NAME_2_TYPE and self.platform_type is not None:
return bool(ADAPTER_NAME_2_TYPE[adapter_name] & self.platform_type)If
|
||||||||||||
|
|
||||||||||||
|
Comment on lines
+65
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||
| adapter_name = event.get_platform_name() | ||||||||||||
| if adapter_name in ADAPTER_NAME_2_TYPE and self.platform_type is not None: | ||||||||||||
| return bool(ADAPTER_NAME_2_TYPE[adapter_name] & self.platform_type) | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an
enum.Flag, usingenum.auto()forALLmakes it a single distinct bit rather than a bitmask of all other members. This breaks the expected behavior of a "match all" flag when performing bitwise operations (e.g.,ALL ^ TELEGRAMwould still matchTELEGRAMbecause theALLbit is checked separately in thefiltermethod). It is better to defineALLas a bitmask OR of all other platform members.