mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
chore: ruff
This commit is contained in:
@@ -13,10 +13,10 @@ import anyio
|
||||
|
||||
from astrbot import logger
|
||||
from astrbot._internal.abc.base_astrbot_orchestrator import BaseAstrbotOrchestrator
|
||||
from astrbot._internal.protocols._mcp.client import McpClient
|
||||
from astrbot._internal.protocols._abp.client import AstrbotAbpClient
|
||||
from astrbot._internal.protocols._acp.client import AstrbotAcpClient
|
||||
from astrbot._internal.protocols._lsp.client import AstrbotLspClient
|
||||
from astrbot._internal.protocols._mcp.client import McpClient
|
||||
from astrbot._internal.stars import RuntimeStatusStar
|
||||
|
||||
log = logger
|
||||
|
||||
@@ -9,8 +9,6 @@ This module provides:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import binascii
|
||||
import hashlib
|
||||
import json
|
||||
import zoneinfo
|
||||
from collections.abc import Callable
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import traceback
|
||||
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
||||
@@ -277,10 +277,8 @@ class DiscordPlatformEvent(AstrMessageEvent):
|
||||
self.message_obj.raw_message, "mentions"
|
||||
):
|
||||
return any(
|
||||
|
||||
mention.id == int(self.message_obj.self_id)
|
||||
for mention in self.message_obj.raw_message.mentions
|
||||
|
||||
mention.id == int(self.message_obj.self_id)
|
||||
for mention in self.message_obj.raw_message.mentions
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
@@ -352,10 +352,7 @@ class LinePlatformAdapter(Platform):
|
||||
if original_name:
|
||||
safe_stem = Path(original_name).stem.strip()
|
||||
safe_stem = "".join(
|
||||
|
||||
ch if ch.isalnum() or ch in ("-", "_", ".") else "_"
|
||||
for ch in safe_stem
|
||||
|
||||
ch if ch.isalnum() or ch in ("-", "_", ".") else "_" for ch in safe_stem
|
||||
)
|
||||
safe_stem = safe_stem.strip("._")
|
||||
if safe_stem:
|
||||
|
||||
@@ -342,19 +342,14 @@ class MisskeyPlatformAdapter(Platform):
|
||||
user_info = self._user_cache.get(user_id_for_cache)
|
||||
text = add_at_mention_if_needed(text, user_info, has_at_user)
|
||||
has_file_components = any(
|
||||
|
||||
isinstance(comp, Comp.Image)
|
||||
or isinstance(comp, Comp.File)
|
||||
or hasattr(comp, "convert_to_file_path")
|
||||
or hasattr(comp, "get_file")
|
||||
or any(
|
||||
|
||||
hasattr(comp, a)
|
||||
for a in ("file", "url", "path", "src", "source")
|
||||
|
||||
)
|
||||
for comp in message_chain.chain
|
||||
|
||||
isinstance(comp, Comp.Image)
|
||||
or isinstance(comp, Comp.File)
|
||||
or hasattr(comp, "convert_to_file_path")
|
||||
or hasattr(comp, "get_file")
|
||||
or any(
|
||||
hasattr(comp, a) for a in ("file", "url", "path", "src", "source")
|
||||
)
|
||||
for comp in message_chain.chain
|
||||
)
|
||||
if not text or not text.strip():
|
||||
if not has_file_components:
|
||||
@@ -445,10 +440,8 @@ class MisskeyPlatformAdapter(Platform):
|
||||
or hasattr(comp, "convert_to_file_path")
|
||||
or hasattr(comp, "get_file")
|
||||
or any(
|
||||
|
||||
hasattr(comp, a)
|
||||
for a in ("file", "url", "path", "src", "source")
|
||||
|
||||
hasattr(comp, a)
|
||||
for a in ("file", "url", "path", "src", "source")
|
||||
)
|
||||
):
|
||||
file_components.append(comp)
|
||||
|
||||
@@ -360,7 +360,9 @@ class EmbeddingProvider(AbstractProvider):
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
errors = [r for r in results if isinstance(r, Exception)]
|
||||
if errors:
|
||||
error_msg = f"有 {len(errors)} 个批次处理失败: {'; '.join(str(e) for e in errors)}"
|
||||
error_msg = (
|
||||
f"有 {len(errors)} 个批次处理失败: {'; '.join(str(e) for e in errors)}"
|
||||
)
|
||||
raise Exception(error_msg)
|
||||
return all_embeddings
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@ try:
|
||||
)
|
||||
|
||||
_MultiModalConversationType: type = MultiModalConversation
|
||||
except ImportError: # pragma: no cover - older dashscope versions without Qwen TTS support
|
||||
except (
|
||||
ImportError
|
||||
): # pragma: no cover - older dashscope versions without Qwen TTS support
|
||||
MultiModalConversation = None # type: ignore
|
||||
_MultiModalConversationType = None # type: ignore
|
||||
|
||||
|
||||
@@ -427,12 +427,10 @@ class ProviderGoogleGenAI(Provider):
|
||||
chain: list[Comp.BaseMessageComponent] = []
|
||||
part: types.Part
|
||||
if all(
|
||||
|
||||
part.inline_data
|
||||
and part.inline_data.mime_type
|
||||
and part.inline_data.mime_type.startswith("image/")
|
||||
for part in result_parts
|
||||
|
||||
part.inline_data
|
||||
and part.inline_data.mime_type
|
||||
and part.inline_data.mime_type.startswith("image/")
|
||||
for part in result_parts
|
||||
):
|
||||
chain.append(Comp.Plain("这是图片"))
|
||||
for part in result_parts:
|
||||
|
||||
Reference in New Issue
Block a user