ruff fix但指定了--unsafe-fixes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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 []
|
||||
|
||||
@@ -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 不能为空")
|
||||
|
||||
Reference in New Issue
Block a user