From cf08e52a9203ee1435ac9da059bab767efad1e9c Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 6 Mar 2025 23:52:15 +0800 Subject: [PATCH] style: cleanup --- astrbot/core/platform/sources/gewechat/gewechat_event.py | 4 +--- .../platform/sources/gewechat/gewechat_platform_adapter.py | 2 -- astrbot/core/platform/sources/telegram/tg_adapter.py | 6 ++++-- astrbot/core/platform/sources/webchat/webchat_adapter.py | 2 +- astrbot/core/platform/sources/webchat/webchat_event.py | 1 + astrbot/core/utils/session_waiter.py | 4 +++- astrbot/dashboard/routes/static_file.py | 2 +- astrbot/dashboard/server.py | 4 +++- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/astrbot/core/platform/sources/gewechat/gewechat_event.py b/astrbot/core/platform/sources/gewechat/gewechat_event.py index 6a13c5bf6..7668663fb 100644 --- a/astrbot/core/platform/sources/gewechat/gewechat_event.py +++ b/astrbot/core/platform/sources/gewechat/gewechat_event.py @@ -136,7 +136,5 @@ class GewechatPlatformEvent(AstrMessageEvent): async def send(self, message: MessageChain): to_wxid = self.message_obj.raw_message.get("to_wxid", None) - await GewechatPlatformEvent.send_with_client( - message, to_wxid, self.client - ) + await GewechatPlatformEvent.send_with_client(message, to_wxid, self.client) await super().send(message) diff --git a/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py b/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py index fe770500d..3dbdbba27 100644 --- a/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py +++ b/astrbot/core/platform/sources/gewechat/gewechat_platform_adapter.py @@ -4,12 +4,10 @@ import os from astrbot.api.platform import Platform, AstrBotMessage, MessageType, PlatformMetadata from astrbot.api.event import MessageChain -from astrbot.api import logger from astrbot.core.platform.astr_message_event import MessageSesion from ...register import register_platform_adapter from .gewechat_event import GewechatPlatformEvent from .client import SimpleGewechatClient -from astrbot.core.message.components import Plain if sys.version_info >= (3, 12): from typing import override diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index f233702f0..528141a09 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -24,7 +24,7 @@ from astrbot.api.platform import register_platform_adapter from telegram import Update from telegram.ext import ApplicationBuilder, ContextTypes, filters from telegram.constants import ChatType -from telegram.ext import MessageHandler as TelegramMessageHandler, CommandHandler +from telegram.ext import MessageHandler as TelegramMessageHandler from .tg_event import TelegramPlatformEvent from astrbot.api import logger from telegram.ext import ExtBot @@ -121,7 +121,9 @@ class TelegramPlatformAdapter(Platform): if update.message.entities: for entity in update.message.entities: if entity.type == "mention": - name = plain_text[entity.offset+1 : entity.offset + entity.length] + name = plain_text[ + entity.offset + 1 : entity.offset + entity.length + ] message.message.append(At(qq=name, name=name)) plain_text = ( plain_text[: entity.offset] diff --git a/astrbot/core/platform/sources/webchat/webchat_adapter.py b/astrbot/core/platform/sources/webchat/webchat_adapter.py index b998e8d9d..12b193f53 100644 --- a/astrbot/core/platform/sources/webchat/webchat_adapter.py +++ b/astrbot/core/platform/sources/webchat/webchat_adapter.py @@ -13,7 +13,7 @@ from astrbot.core.platform import ( from astrbot.core.message.message_event_result import MessageChain from astrbot.core.message.components import Plain, Image, Record # noqa: F403 from astrbot import logger -from astrbot.core import web_chat_queue, web_chat_back_queue +from astrbot.core import web_chat_queue from .webchat_event import WebChatMessageEvent from astrbot.core.platform.astr_message_event import MessageSesion from ...register import register_platform_adapter diff --git a/astrbot/core/platform/sources/webchat/webchat_event.py b/astrbot/core/platform/sources/webchat/webchat_event.py index 49a4a2cfd..fb42080db 100644 --- a/astrbot/core/platform/sources/webchat/webchat_event.py +++ b/astrbot/core/platform/sources/webchat/webchat_event.py @@ -9,6 +9,7 @@ from astrbot.core import web_chat_back_queue imgs_dir = "data/webchat/imgs" + class WebChatMessageEvent(AstrMessageEvent): def __init__(self, message_str, message_obj, platform_meta, session_id): super().__init__(message_str, message_obj, platform_meta, session_id) diff --git a/astrbot/core/utils/session_waiter.py b/astrbot/core/utils/session_waiter.py index 7b0c7855f..7ba8ddfb4 100644 --- a/astrbot/core/utils/session_waiter.py +++ b/astrbot/core/utils/session_waiter.py @@ -139,7 +139,9 @@ class SessionWaiter: session.session_controller.stop(e) -def session_waiter(session_id_param: str, timeout: int = 30, record_history_chains: bool = False): +def session_waiter( + session_id_param: str, timeout: int = 30, record_history_chains: bool = False +): """ 装饰器:自动将函数注册为 SessionWaiter 处理函数,并等待外部输入触发执行。 diff --git a/astrbot/dashboard/routes/static_file.py b/astrbot/dashboard/routes/static_file.py index 09b538fee..7a673fd15 100644 --- a/astrbot/dashboard/routes/static_file.py +++ b/astrbot/dashboard/routes/static_file.py @@ -19,7 +19,7 @@ class StaticFileRoute(Route): "/platforms", "/providers", "/about", - "/extension-marketplace" + "/extension-marketplace", ] for i in index_: self.app.add_url_rule(i, view_func=self.index) diff --git a/astrbot/dashboard/server.py b/astrbot/dashboard/server.py index 3bb077670..42bbad318 100644 --- a/astrbot/dashboard/server.py +++ b/astrbot/dashboard/server.py @@ -25,7 +25,9 @@ class AstrBotDashboard: self.config = core_lifecycle.astrbot_config self.data_path = os.path.abspath(os.path.join(DATAPATH, "dist")) self.app = Quart("dashboard", static_folder=self.data_path, static_url_path="/") - self.app.config['MAX_CONTENT_LENGTH'] = 128 * 1024 * 1024 # 将 Flask 允许的最大上传文件体大小设置为 128 MB + self.app.config["MAX_CONTENT_LENGTH"] = ( + 128 * 1024 * 1024 + ) # 将 Flask 允许的最大上传文件体大小设置为 128 MB self.app.json.sort_keys = False self.app.before_request(self.auth_middleware) # token 用于验证请求