ruff fix但指定了--unsafe-fixes

This commit is contained in:
minecraft1024a
2025-10-05 21:48:32 +08:00
committed by Windpicker-owo
parent 04feb585b4
commit 2a89efe47a
76 changed files with 301 additions and 316 deletions

View File

@@ -57,60 +57,60 @@ from .utils.dependency_manager import configure_dependency_manager, get_dependen
__version__ = "2.0.0"
__all__ = [
"ActionActivationType",
"ActionInfo",
"BaseAction",
"BaseCommand",
"BaseEventHandler",
# 基础类
"BasePlugin",
"BaseTool",
"ChatMode",
"ChatType",
"CommandArgs",
"CommandInfo",
"ComponentInfo",
# 类型定义
"ComponentType",
"ConfigField",
"EventHandlerInfo",
"EventType",
# 消息
"MaiMessages",
# 工具函数
"ManifestValidator",
"PluginInfo",
# 增强命令系统
"PlusCommand",
"PlusCommandAdapter",
"PythonDependency",
"ToolInfo",
"ToolParamType",
# API 模块
"chat_api",
"tool_api",
"component_manage_api",
"config_api",
"configure_dependency_manager",
"configure_dependency_settings",
"create_plus_command_adapter",
"create_plus_command_adapter",
"database_api",
"emoji_api",
"generator_api",
"get_dependency_config",
# 依赖管理
"get_dependency_manager",
"get_logger",
"get_logger",
"llm_api",
"message_api",
"person_api",
"plugin_manage_api",
"send_api",
"register_plugin",
"get_logger",
# 基础类
"BasePlugin",
"BaseAction",
"BaseCommand",
"BaseTool",
"BaseEventHandler",
# 增强命令系统
"PlusCommand",
"CommandArgs",
"PlusCommandAdapter",
"create_plus_command_adapter",
"create_plus_command_adapter",
# 类型定义
"ComponentType",
"ActionActivationType",
"ChatMode",
"ChatType",
"ComponentInfo",
"ActionInfo",
"CommandInfo",
"PluginInfo",
"ToolInfo",
"PythonDependency",
"EventHandlerInfo",
"EventType",
"ToolParamType",
# 消息
"MaiMessages",
# 装饰器
"register_plugin",
"ConfigField",
# 工具函数
"ManifestValidator",
"get_logger",
# 依赖管理
"get_dependency_manager",
"configure_dependency_manager",
"get_dependency_config",
"configure_dependency_settings",
"send_api",
"tool_api",
# "ManifestGenerator",
# "validate_plugin_manifest",
# "generate_plugin_manifest",

View File

@@ -44,11 +44,11 @@ class ChatManager:
Raises:
TypeError: 如果 platform 不是字符串或 SpecialTypes 枚举类型
"""
if not isinstance(platform, (str, SpecialTypes)):
if not isinstance(platform, str | SpecialTypes):
raise TypeError("platform 必须是字符串或是 SpecialTypes 枚举")
streams = []
try:
for _, stream in get_chat_manager().streams.items():
for stream in get_chat_manager().streams.values():
if platform == SpecialTypes.ALL_PLATFORMS or stream.platform == platform:
streams.append(stream)
logger.debug(f"[ChatAPI] 获取到 {len(streams)}{platform} 平台的聊天流")
@@ -67,11 +67,11 @@ class ChatManager:
Returns:
List[ChatStream]: 群聊聊天流列表
"""
if not isinstance(platform, (str, SpecialTypes)):
if not isinstance(platform, str | SpecialTypes):
raise TypeError("platform 必须是字符串或是 SpecialTypes 枚举")
streams = []
try:
for _, stream in get_chat_manager().streams.items():
for stream in get_chat_manager().streams.values():
if (platform == SpecialTypes.ALL_PLATFORMS or stream.platform == platform) and stream.group_info:
streams.append(stream)
logger.debug(f"[ChatAPI] 获取到 {len(streams)}{platform} 平台的群聊流")
@@ -93,11 +93,11 @@ class ChatManager:
Raises:
TypeError: 如果 platform 不是字符串或 SpecialTypes 枚举类型
"""
if not isinstance(platform, (str, SpecialTypes)):
if not isinstance(platform, str | SpecialTypes):
raise TypeError("platform 必须是字符串或是 SpecialTypes 枚举")
streams = []
try:
for _, stream in get_chat_manager().streams.items():
for stream in get_chat_manager().streams.values():
if (platform == SpecialTypes.ALL_PLATFORMS or stream.platform == platform) and not stream.group_info:
streams.append(stream)
logger.debug(f"[ChatAPI] 获取到 {len(streams)}{platform} 平台的私聊流")
@@ -124,12 +124,12 @@ class ChatManager:
"""
if not isinstance(group_id, str):
raise TypeError("group_id 必须是字符串类型")
if not isinstance(platform, (str, SpecialTypes)):
if not isinstance(platform, str | SpecialTypes):
raise TypeError("platform 必须是字符串或是 SpecialTypes 枚举")
if not group_id:
raise ValueError("group_id 不能为空")
try:
for _, stream in get_chat_manager().streams.items():
for stream in get_chat_manager().streams.values():
if (
stream.group_info
and str(stream.group_info.group_id) == str(group_id)
@@ -161,12 +161,12 @@ class ChatManager:
"""
if not isinstance(user_id, str):
raise TypeError("user_id 必须是字符串类型")
if not isinstance(platform, (str, SpecialTypes)):
if not isinstance(platform, str | SpecialTypes):
raise TypeError("platform 必须是字符串或是 SpecialTypes 枚举")
if not user_id:
raise ValueError("user_id 不能为空")
try:
for _, stream in get_chat_manager().streams.items():
for stream in get_chat_manager().streams.values():
if (
not stream.group_info
and str(stream.user_info.user_id) == str(user_id)

View File

@@ -13,7 +13,6 @@ from src.chat.utils.chat_message_builder import (
)
from src.common.logger import get_logger
from src.config.config import global_config
from src.plugin_system.apis import config_api
logger = get_logger("cross_context_api")

View File

@@ -240,7 +240,7 @@ def get_emotions() -> list[str]:
if not emoji_obj.is_deleted and emoji_obj.emotion:
emotions.update(emoji_obj.emotion)
return sorted(list(emotions))
return sorted(emotions)
except Exception as e:
logger.error(f"[EmojiAPI] 获取情感标签失败: {e}")
return []

View File

@@ -53,7 +53,7 @@ async def get_messages_by_time(
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(start_time, (int, float)) or not isinstance(end_time, (int, float)):
if not isinstance(start_time, int | float) or not isinstance(end_time, int | float):
raise ValueError("start_time 和 end_time 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -88,7 +88,7 @@ async def get_messages_by_time_in_chat(
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(start_time, (int, float)) or not isinstance(end_time, (int, float)):
if not isinstance(start_time, int | float) or not isinstance(end_time, int | float):
raise ValueError("start_time 和 end_time 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -129,7 +129,7 @@ async def get_messages_by_time_in_chat_inclusive(
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(start_time, (int, float)) or not isinstance(end_time, (int, float)):
if not isinstance(start_time, int | float) or not isinstance(end_time, int | float):
raise ValueError("start_time 和 end_time 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -173,7 +173,7 @@ async def get_messages_by_time_in_chat_for_users(
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(start_time, (int, float)) or not isinstance(end_time, (int, float)):
if not isinstance(start_time, int | float) or not isinstance(end_time, int | float):
raise ValueError("start_time 和 end_time 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -203,7 +203,7 @@ async def get_random_chat_messages(
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(start_time, (int, float)) or not isinstance(end_time, (int, float)):
if not isinstance(start_time, int | float) or not isinstance(end_time, int | float):
raise ValueError("start_time 和 end_time 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -231,7 +231,7 @@ async def get_messages_by_time_for_users(
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(start_time, (int, float)) or not isinstance(end_time, (int, float)):
if not isinstance(start_time, int | float) or not isinstance(end_time, int | float):
raise ValueError("start_time 和 end_time 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -253,7 +253,7 @@ async def get_messages_before_time(timestamp: float, limit: int = 0, filter_mai:
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(timestamp, (int, float)):
if not isinstance(timestamp, int | float):
raise ValueError("timestamp 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -280,7 +280,7 @@ async def get_messages_before_time_in_chat(
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(timestamp, (int, float)):
if not isinstance(timestamp, int | float):
raise ValueError("timestamp 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -310,7 +310,7 @@ async def get_messages_before_time_for_users(
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(timestamp, (int, float)):
if not isinstance(timestamp, int | float):
raise ValueError("timestamp 必须是数字类型")
if limit < 0:
raise ValueError("limit 不能为负数")
@@ -336,7 +336,7 @@ async def get_recent_messages(
Raises:
ValueError: 如果参数不合法s
"""
if not isinstance(hours, (int, float)) or hours < 0:
if not isinstance(hours, int | float) or hours < 0:
raise ValueError("hours 不能是负数")
if not isinstance(limit, int) or limit < 0:
raise ValueError("limit 必须是非负整数")
@@ -373,7 +373,7 @@ async def count_new_messages(chat_id: str, start_time: float = 0.0, end_time: fl
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(start_time, (int, float)):
if not isinstance(start_time, int | float):
raise ValueError("start_time 必须是数字类型")
if not chat_id:
raise ValueError("chat_id 不能为空")
@@ -398,7 +398,7 @@ async def count_new_messages_for_users(chat_id: str, start_time: float, end_time
Raises:
ValueError: 如果参数不合法
"""
if not isinstance(start_time, (int, float)) or not isinstance(end_time, (int, float)):
if not isinstance(start_time, int | float) or not isinstance(end_time, int | float):
raise ValueError("start_time 和 end_time 必须是数字类型")
if not chat_id:
raise ValueError("chat_id 不能为空")

View File

@@ -31,30 +31,30 @@ from .config_types import ConfigField
from .plus_command import PlusCommand, PlusCommandAdapter, create_plus_command_adapter
__all__ = [
"BasePlugin",
"ActionActivationType",
"ActionInfo",
"BaseAction",
"BaseCommand",
"BaseEventHandler",
"BasePlugin",
"BaseTool",
"ComponentType",
"ActionActivationType",
"ChatMode",
"ChatType",
"ComponentInfo",
"ActionInfo",
"CommandArgs",
"CommandInfo",
"PlusCommandInfo",
"ToolInfo",
"PluginInfo",
"PythonDependency",
"ComponentInfo",
"ComponentType",
"ConfigField",
"EventHandlerInfo",
"EventType",
"BaseEventHandler",
"MaiMessages",
"ToolParamType",
"PluginInfo",
# 增强命令系统
"PlusCommand",
"CommandArgs",
"PlusCommandAdapter",
"PlusCommandInfo",
"PythonDependency",
"ToolInfo",
"ToolParamType",
"create_plus_command_adapter",
]

View File

@@ -528,7 +528,7 @@ class BaseAction(ABC):
selected_action = self.action_data.get("selected_action")
if not selected_action:
# 第一步展示可用的子Action
available_actions = [sub_action[0] for sub_action in self.sub_actions]
[sub_action[0] for sub_action in self.sub_actions]
description = self.step_one_description or f"{self.action_name}支持以下操作"
actions_list = "\n".join([f"- {action}: {desc}" for action, desc, _ in self.sub_actions])

View File

@@ -86,7 +86,7 @@ class HandlerResultsCollection:
class BaseEvent:
def __init__(self, name: str, allowed_subscribers: list[str] = None, allowed_triggers: list[str] = None):
def __init__(self, name: str, allowed_subscribers: list[str] | None = None, allowed_triggers: list[str] | None = None):
self.name = name
self.enabled = True
self.allowed_subscribers = allowed_subscribers # 记录事件处理器名

View File

@@ -316,7 +316,7 @@ class PlusCommand(ABC):
str: 正则表达式字符串
"""
# 获取所有可能的命令名(主命令名 + 别名)
all_commands = [cls.command_name] + getattr(cls, "command_aliases", [])
all_commands = [cls.command_name, *getattr(cls, "command_aliases", [])]
# 转义特殊字符并创建选择组
escaped_commands = [re.escape(cmd) for cmd in all_commands]

View File

@@ -836,8 +836,6 @@ class ComponentRegistry:
},
"enabled_components": len([c for c in self._components.values() if c.enabled]),
"enabled_plugins": len([p for p in self._plugins.values() if p.enabled]),
"enabled_components": len([c for c in self._components.values() if c.enabled]),
"enabled_plugins": len([p for p in self._plugins.values() if p.enabled]),
}
# === 组件移除相关 ===

View File

@@ -46,8 +46,8 @@ class EventManager:
def register_event(
self,
event_name: EventType | str,
allowed_subscribers: list[str] = None,
allowed_triggers: list[str] = None,
allowed_subscribers: list[str] | None = None,
allowed_triggers: list[str] | None = None,
) -> bool:
"""注册一个新的事件

View File

@@ -138,7 +138,7 @@ class ToolExecutor:
pending_step_two = getattr(self, "_pending_step_two_tools", {})
if pending_step_two:
# 添加第二步工具定义
for tool_name, step_two_def in pending_step_two.items():
for step_two_def in pending_step_two.values():
tool_definitions.append(step_two_def)
return tool_definitions
@@ -192,7 +192,7 @@ class ToolExecutor:
"timestamp": time.time(),
}
content = tool_info["content"]
if not isinstance(content, (str, list, tuple)):
if not isinstance(content, str | list | tuple):
tool_info["content"] = str(content)
tool_results.append(tool_info)