perf(methods): 通过移除不必要的 self 参数优化方法签名
在包括 chat、plugin_system、schedule 和 mais4u 在内的多个模块中,消除冗余的实例引用。此次改动将无需访问实例状态的实用函数转换为静态方法,从而提升了内存效率,并使方法依赖关系更加清晰。
This commit is contained in:
@@ -162,7 +162,8 @@ class DependencyManager:
|
||||
|
||||
return False, all_errors
|
||||
|
||||
def _normalize_dependencies(self, dependencies: Any) -> List[PythonDependency]:
|
||||
@staticmethod
|
||||
def _normalize_dependencies(dependencies: Any) -> List[PythonDependency]:
|
||||
"""将依赖列表标准化为PythonDependency对象"""
|
||||
normalized = []
|
||||
|
||||
@@ -191,7 +192,8 @@ class DependencyManager:
|
||||
|
||||
return normalized
|
||||
|
||||
def _check_single_dependency(self, dep: PythonDependency) -> bool:
|
||||
@staticmethod
|
||||
def _check_single_dependency(dep: PythonDependency) -> bool:
|
||||
"""检查单个依赖是否满足要求"""
|
||||
|
||||
def _try_check(import_name: str) -> bool:
|
||||
|
||||
@@ -82,10 +82,10 @@ class VersionComparator:
|
||||
normalized = VersionComparator.normalize_version(version)
|
||||
try:
|
||||
parts = normalized.split(".")
|
||||
return (int(parts[0]), int(parts[1]), int(parts[2]))
|
||||
return int(parts[0]), int(parts[1]), int(parts[2])
|
||||
except (ValueError, IndexError):
|
||||
logger.warning(f"无法解析版本号: {version},使用默认版本 0.0.0")
|
||||
return (0, 0, 0)
|
||||
return 0, 0, 0
|
||||
|
||||
@staticmethod
|
||||
def compare_versions(version1: str, version2: str) -> int:
|
||||
|
||||
@@ -58,7 +58,7 @@ def require_permission(permission_node: str, deny_message: Optional[str] = None)
|
||||
|
||||
if chat_stream is None:
|
||||
logger.error(f"权限装饰器无法找到 ChatStream 对象,函数: {func.__name__}")
|
||||
return
|
||||
return None
|
||||
|
||||
# 检查权限
|
||||
has_permission = permission_api.check_permission(
|
||||
@@ -72,7 +72,7 @@ def require_permission(permission_node: str, deny_message: Optional[str] = None)
|
||||
# 对于PlusCommand的execute方法,需要返回适当的元组
|
||||
if func.__name__ == "execute" and hasattr(args[0], "send_text"):
|
||||
return False, "权限不足", True
|
||||
return
|
||||
return None
|
||||
|
||||
# 权限检查通过,执行原函数
|
||||
return await func(*args, **kwargs)
|
||||
@@ -90,7 +90,7 @@ def require_permission(permission_node: str, deny_message: Optional[str] = None)
|
||||
|
||||
if chat_stream is None:
|
||||
logger.error(f"权限装饰器无法找到 ChatStream 对象,函数: {func.__name__}")
|
||||
return
|
||||
return None
|
||||
|
||||
# 检查权限
|
||||
has_permission = permission_api.check_permission(
|
||||
@@ -101,7 +101,7 @@ def require_permission(permission_node: str, deny_message: Optional[str] = None)
|
||||
logger.warning(
|
||||
f"用户 {chat_stream.platform}:{chat_stream.user_info.user_id} 没有权限 {permission_node}"
|
||||
)
|
||||
return
|
||||
return None
|
||||
|
||||
# 权限检查通过,执行原函数
|
||||
return func(*args, **kwargs)
|
||||
@@ -156,7 +156,7 @@ def require_master(deny_message: Optional[str] = None):
|
||||
|
||||
if chat_stream is None:
|
||||
logger.error(f"Master权限装饰器无法找到 ChatStream 对象,函数: {func.__name__}")
|
||||
return
|
||||
return None
|
||||
|
||||
# 检查是否为Master用户
|
||||
is_master = permission_api.is_master(chat_stream.platform, chat_stream.user_info.user_id)
|
||||
@@ -166,7 +166,7 @@ def require_master(deny_message: Optional[str] = None):
|
||||
await text_to_stream(message, chat_stream.stream_id)
|
||||
if func.__name__ == "execute" and hasattr(args[0], "send_text"):
|
||||
return False, "需要Master权限", True
|
||||
return
|
||||
return None
|
||||
|
||||
# 权限检查通过,执行原函数
|
||||
return await func(*args, **kwargs)
|
||||
@@ -184,14 +184,14 @@ def require_master(deny_message: Optional[str] = None):
|
||||
|
||||
if chat_stream is None:
|
||||
logger.error(f"Master权限装饰器无法找到 ChatStream 对象,函数: {func.__name__}")
|
||||
return
|
||||
return None
|
||||
|
||||
# 检查是否为Master用户
|
||||
is_master = permission_api.is_master(chat_stream.platform, chat_stream.user_info.user_id)
|
||||
|
||||
if not is_master:
|
||||
logger.warning(f"用户 {chat_stream.platform}:{chat_stream.user_info.user_id} 不是Master用户")
|
||||
return
|
||||
return None
|
||||
|
||||
# 权限检查通过,执行原函数
|
||||
return func(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user