@@ -496,10 +496,11 @@ def add(text: object) -> None:
496496 candidates .append (normalized )
497497
498498 add (_trie_command_text_from_state (state ))
499- add (_trie_raw_command_from_state (state ))
499+ trie_raw = _trie_raw_command_from_state (state )
500+ add (trie_raw )
500501 trie_arg = _trie_command_arg_text_from_state (state )
501- if _trie_raw_command_from_state ( state ) and trie_arg :
502- add (f"{ _trie_raw_command_from_state ( state ) } { trie_arg } " )
502+ if trie_raw and trie_arg :
503+ add (f"{ trie_raw } { trie_arg } " )
503504 add (plain_text )
504505 if event is not None :
505506 with contextlib .suppress (Exception ):
@@ -794,9 +795,10 @@ def _prepare_handle_event_state(event: Event, state: dict) -> None:
794795
795796
796797def _build_matcher_state (base_state : dict ) -> dict :
798+ # 第一次调用即在 base_state 写入副作用缓存对象;copy() 后 matcher_state
799+ # 与之共享同一引用,无需二次 get(B7)。
797800 get_permission_side_effect_cache (state = base_state )
798801 matcher_state = base_state .copy ()
799- get_permission_side_effect_cache (state = matcher_state )
800802 return matcher_state
801803
802804
@@ -965,25 +967,28 @@ async def _db_section():
965967 DB_ACTIVE_COUNT = max (DB_ACTIVE_COUNT - 1 , 0 )
966968
967969
970+ _POLICY_SKIP_MESSAGES = {
971+ "user_or_group_banned" : "user or group banned (cached)" ,
972+ "superuser_required" : "超级管理员权限不足..." ,
973+ "admin_required" : "管理员权限不足..." ,
974+ "bot_not_found" : "Bot不存在,阻断权限检测..." ,
975+ "bot_sleeping" : "Bot休眠中阻断权限检测..." ,
976+ "bot_plugin_blocked" : "Bot插件权限检查结果为关闭..." ,
977+ "group_not_found" : "群组信息不存在..." ,
978+ "group_blacklisted" : "群组黑名单, 目标群组群权限权限-1..." ,
979+ "group_sleeping" : "群组休眠状态..." ,
980+ "group_level_low" : "群等级限制..." ,
981+ "admin_level_low" : "管理员权限不足..." ,
982+ "plugin_disabled_in_group" : "该插件在群组中已被禁用..." ,
983+ "plugin_superuser_blocked_in_group" : "超级管理员禁用了该群此功能..." ,
984+ "plugin_blocked_in_group" : "该群未开启此功能..." ,
985+ "plugin_disabled_in_private" : "该插件在私聊中已被禁用..." ,
986+ "plugin_global_disabled" : "全局未开启此功能..." ,
987+ }
988+
989+
968990def _policy_skip_message (reason : str ) -> str :
969- return {
970- "user_or_group_banned" : "user or group banned (cached)" ,
971- "superuser_required" : "超级管理员权限不足..." ,
972- "admin_required" : "管理员权限不足..." ,
973- "bot_not_found" : "Bot不存在,阻断权限检测..." ,
974- "bot_sleeping" : "Bot休眠中阻断权限检测..." ,
975- "bot_plugin_blocked" : "Bot插件权限检查结果为关闭..." ,
976- "group_not_found" : "群组信息不存在..." ,
977- "group_blacklisted" : "群组黑名单, 目标群组群权限权限-1..." ,
978- "group_sleeping" : "群组休眠状态..." ,
979- "group_level_low" : "群等级限制..." ,
980- "admin_level_low" : "管理员权限不足..." ,
981- "plugin_disabled_in_group" : "该插件在群组中已被禁用..." ,
982- "plugin_superuser_blocked_in_group" : "超级管理员禁用了该群此功能..." ,
983- "plugin_blocked_in_group" : "该群未开启此功能..." ,
984- "plugin_disabled_in_private" : "该插件在私聊中已被禁用..." ,
985- "plugin_global_disabled" : "全局未开启此功能..." ,
986- }.get (reason , reason or "permission denied" )
991+ return _POLICY_SKIP_MESSAGES .get (reason , reason or "permission denied" )
987992
988993
989994# 超时装饰器
@@ -1342,18 +1347,24 @@ async def _check_ban_from_snapshot(
13421347 hook_recorder : HookTraceRecorder ,
13431348 session : Uninfo ,
13441349) -> None :
1350+ # skip_ban 上移到 cached 判断之前(A7),否则豁免参数对 cached 命中形同虚设。
1351+ if skip_ban :
1352+ hook_recorder .set ("auth_ban" , "skipped" )
1353+ return
1354+ is_superuser = bool (getattr (prep .permission_context , "is_superuser" , False ))
13451355 ban_cache_state = prep .snapshot .ban_state
13461356 if event_cache is not None :
13471357 ban_cache_state = event_cache .get ("ban_state" )
13481358 if ban_cache_state is True :
1359+ # 超级用户豁免(A7):与 PDP / 旧轨权威路径保持一致,避免被 ban 后无法自救。
1360+ if is_superuser :
1361+ hook_recorder .set ("auth_ban" , "cached_superuser_exempt" )
1362+ return
13491363 hook_recorder .set ("auth_ban" , "cached" )
13501364 raise SkipPluginException ("user or group banned (cached)" )
13511365 if ban_cache_state is False :
13521366 hook_recorder .set ("auth_ban" , "cached" )
13531367 return
1354- if skip_ban :
1355- hook_recorder .set ("auth_ban" , "skipped" )
1356- return
13571368
13581369 ban_start = time .time ()
13591370 try :
0 commit comments