chore: cleanup

This commit is contained in:
Soulter
2025-02-16 13:32:28 +08:00
parent ebb8c43fd0
commit 26cbc9e8b1
3 changed files with 16 additions and 23 deletions
+2
View File
@@ -16,6 +16,7 @@ from astrbot.core.star.register import (
from astrbot.core.star.filter.event_message_type import EventMessageTypeFilter, EventMessageType
from astrbot.core.star.filter.platform_adapter_type import PlatformAdapterTypeFilter, PlatformAdapterType
from astrbot.core.star.filter.permission import PermissionTypeFilter, PermissionType
from astrbot.core.star.filter.custom_filter import CustomFilter
__all__ = [
'command',
@@ -29,6 +30,7 @@ __all__ = [
'PlatformAdapterTypeFilter',
'PlatformAdapterType',
'PermissionTypeFilter',
'CustomFilter',
'custom_filter',
'PermissionType',
'on_llm_request',
+11 -20
View File
@@ -24,23 +24,18 @@ class CommandGroupFilter(HandlerFilter):
# 以树的形式打印出来
def print_cmd_tree(self,
sub_command_filters: List[Union[CommandFilter,
CommandGroupFilter]],
prefix: str = "",
event: AstrMessageEvent = None,
cfg: AstrBotConfig = None,
) -> str:
sub_command_filters: List[Union[CommandFilter, CommandGroupFilter]],
prefix: str = "",
event: AstrMessageEvent = None,
cfg: AstrBotConfig = None,
) -> str:
result = ""
for sub_filter in sub_command_filters:
if isinstance(sub_filter, CommandFilter):
custom_filter_pass = True
if event and cfg:
if sub_filter.custom_filter_ok(event, cfg):
permission_pass = True
else:
permission_pass = False
else:
permission_pass = True
if permission_pass:
custom_filter_pass = sub_filter.custom_filter_ok(event, cfg)
if custom_filter_pass:
cmd_th = sub_filter.print_types()
result += f"{prefix}├── {sub_filter.command_name}"
if cmd_th:
@@ -49,14 +44,10 @@ class CommandGroupFilter(HandlerFilter):
result += " (无参数指令)"
result += "\n"
elif isinstance(sub_filter, CommandGroupFilter):
custom_filter_pass = True
if event and cfg:
if sub_filter.custom_filter_ok(event, cfg):
permission_pass = True
else:
permission_pass = False
else:
permission_pass = True
if permission_pass:
custom_filter_pass = sub_filter.custom_filter_ok(event, cfg)
if custom_filter_pass:
result += f"{prefix}├── {sub_filter.group_name}"
result += "\n"
result += sub_filter.print_cmd_tree(sub_filter.sub_command_filters, prefix+"", event=event, cfg=cfg)
+3 -3
View File
@@ -85,7 +85,7 @@ def register_custom_filter(custom_type_filter, *args, **kwargs):
'''注册一个自定义的 CustomFilter
Args:
cunstom_permission_type_filter: 在裸指令时为CustomFilter对象
custom_type_filter: 在裸指令时为CustomFilter对象
在指令组时为父指令的RegisteringCommandable对象,即self或者command_group的返回
raise_error: 如果没有权限,是否抛出错误到消息平台,并且停止事件传播。默认为 True
'''
@@ -95,7 +95,7 @@ def register_custom_filter(custom_type_filter, *args, **kwargs):
# 判断是否是指令组,指令组则添加到指令组的CommandGroupFilter对象中在waking_check的时候一起判断
if isinstance(custom_type_filter, RegisteringCommandable):
# 子指令, 此时函数为RegisteringCommandable对象的方法,首位参数为RegisteringCommandable对象的self。
parent_rigister_commandable = custom_type_filter
parent_register_commandable = custom_type_filter
custom_filter = args[0]
if len(args) > 1:
raise_error = args[1]
@@ -121,7 +121,7 @@ def register_custom_filter(custom_type_filter, *args, **kwargs):
if not add_to_event_filters and not isinstance(awaitable, RegisteringCommandable):
# 底层子指令
handle_full_name = get_handler_full_name(awaitable)
for sub_handle in parent_rigister_commandable.parent_group.sub_command_filters:
for sub_handle in parent_register_commandable.parent_group.sub_command_filters:
# 所有符合fullname一致的子指令handle添加自定义过滤器。
# 不确定是否会有多个子指令有一样的fullname,比如一个方法添加多个command装饰器?
sub_handle_md = sub_handle.get_handler_md()