diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index f73c44d3b..2d129eb6d 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -18,6 +18,7 @@ DEFAULT_CONFIG = { "reply_prefix": "", "forward_threshold": 200, "id_whitelist": [], + "id_whitelist_log": True, "wl_ignore_admin_on_group": True, "wl_ignore_admin_on_friend": True, }, @@ -167,6 +168,11 @@ CONFIG_METADATA_2 = { "items": {"type": "int"}, "hint": "填写后,将只处理所填写的 ID 发来的消息事件。为空时表示不启用白名单过滤。可以使用 /myid 指令获取在某个平台上的会话 ID。也可在 AstrBot 日志内获取会话 ID,当一条消息没通过白名单时,会输出 INFO 级别的日志。会话 ID 类似 aiocqhttp:GroupMessage:547540978", }, + "id_whitelist_log": { + "description": "打印白名单日志", + "type": "bool", + "hint": "启用后,当一条消息没通过白名单时,会输出 INFO 级别的日志。", + }, "wl_ignore_admin_on_group": { "description": "管理员群组消息无视 ID 白名单", "type": "bool", diff --git a/astrbot/core/pipeline/whitelist_check/stage.py b/astrbot/core/pipeline/whitelist_check/stage.py index 983b6f138..b2b713a6a 100644 --- a/astrbot/core/pipeline/whitelist_check/stage.py +++ b/astrbot/core/pipeline/whitelist_check/stage.py @@ -13,7 +13,8 @@ class WhitelistCheckStage(Stage): self.whitelist = ctx.astrbot_config['platform_settings']['id_whitelist'] self.wl_ignore_admin_on_group = ctx.astrbot_config['platform_settings']['wl_ignore_admin_on_group'] self.wl_ignore_admin_on_friend = ctx.astrbot_config['platform_settings']['wl_ignore_admin_on_friend'] - + self.wl_log = ctx.astrbot_config['platform_settings']['id_whitelist_log'] + async def process(self, event: AstrMessageEvent) -> Union[None, AsyncGenerator[None, None]]: # 检查是否在白名单 if self.wl_ignore_admin_on_group: @@ -23,5 +24,6 @@ class WhitelistCheckStage(Stage): if event.role == 'admin' and event.get_message_type() == MessageType.FRIEND_MESSAGE: return if event.unified_msg_origin not in self.whitelist: - logger.info(f"会话 {event.unified_msg_origin} 不在会话白名单中,已终止事件传播。") + if self.wl_log: + logger.info(f"会话 ID {event.unified_msg_origin} 不在会话白名单中,已终止事件传播。请在配置文件中添加该会话 ID 到白名单。") event.stop_event() \ No newline at end of file diff --git a/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py b/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py index 007b64a86..0f73ed5fb 100644 --- a/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py +++ b/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py @@ -63,8 +63,6 @@ class QQOfficialPlatformAdapter(Platform): def __init__(self, platform_config: dict, platform_settings: dict, event_queue: asyncio.Queue) -> None: super().__init__(event_queue) - self.loop = asyncio.new_event_loop() - asyncio.set_event_loop(self.loop) self.config = platform_config diff --git a/astrbot/dashboard/dashboard_lifecycle.py b/astrbot/dashboard/dashboard_lifecycle.py index 7563f3137..176ca4dc1 100644 --- a/astrbot/dashboard/dashboard_lifecycle.py +++ b/astrbot/dashboard/dashboard_lifecycle.py @@ -3,17 +3,19 @@ from astrbot.core import logger from astrbot.core.core_lifecycle import AstrBotCoreLifecycle from .server import AstrBotDashboard from astrbot.core.db import BaseDatabase - +from astrbot.core import LogBroker class AstrBotDashBoardLifecycle: - def __init__(self, db: BaseDatabase): + def __init__(self, db: BaseDatabase, log_broker: LogBroker): self.db = db self.logger = logger + self.log_broker = log_broker self.dashboard_server = None - async def start(self, core_lifecycle: AstrBotCoreLifecycle): + async def start(self): + core_lifecycle = AstrBotCoreLifecycle(self.log_broker, self.db) + await core_lifecycle.initialize() core_task = core_lifecycle.start() self.dashboard_server = AstrBotDashboard(core_lifecycle, self.db) - task = asyncio.gather(core_task, self.dashboard_server.run()) try: diff --git a/main.py b/main.py index f268257e0..104de9552 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,6 @@ import sys import mimetypes import aiohttp import zipfile -from astrbot.core.core_lifecycle import AstrBotCoreLifecycle from astrbot.dashboard import AstrBotDashBoardLifecycle from astrbot.core import db_helper from astrbot.core import logger, LogManager, LogBroker @@ -94,8 +93,5 @@ if __name__ == "__main__": # print logo logger.info(logo_tmpl) - core_lifecycle = AstrBotCoreLifecycle(log_broker, db) - asyncio.run(core_lifecycle.initialize()) - - dashboard_lifecycle = AstrBotDashBoardLifecycle(db) - asyncio.run(dashboard_lifecycle.start(core_lifecycle)) \ No newline at end of file + dashboard_lifecycle = AstrBotDashBoardLifecycle(db, log_broker) + asyncio.run(dashboard_lifecycle.start()) \ No newline at end of file