From 91cc21e7298f5029d5ddca8542ecffc8c74394b5 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 15 Dec 2024 11:54:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=AA=E6=89=BE?= =?UTF-8?q?=E5=88=B0=E9=80=82=E7=94=A8=E4=BA=8Eqq=5Fofficial=E7=9A=84?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E9=80=82=E9=85=8D=E5=99=A8=20#223?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/manager.py | 4 ++-- .../qqofficial/qqofficial_platform_adapter.py | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/astrbot/core/platform/manager.py b/astrbot/core/platform/manager.py index 7ae460f92..e9e361e29 100644 --- a/astrbot/core/platform/manager.py +++ b/astrbot/core/platform/manager.py @@ -21,8 +21,8 @@ class PlatformManager(): match platform['type']: case "aiocqhttp": from .sources.aiocqhttp.aiocqhttp_platform_adapter import AiocqhttpAdapter # noqa: F401 - case "qqofficial": - from .sources.qqofficial.qqofficial_platform_adapter import QQOfficialAdapter # noqa: F401 + case "qq_official": + from .sources.qqofficial.qqofficial_platform_adapter import QQOfficialPlatformAdapter # noqa: F401 case "vchat": from .sources.vchat.vchat_platform_adapter import VChatPlatformAdapter # noqa: F401 diff --git a/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py b/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py index 1a7fd7044..007b64a86 100644 --- a/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py +++ b/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py @@ -1,21 +1,27 @@ import botpy +import logging import time import asyncio import botpy.message import botpy.types import botpy.types.message +import os from botpy import Client from astrbot.api.platform import Platform, AstrBotMessage, MessageMember, MessageType, PlatformMetadata from astrbot.api.event import MessageChain from typing import Union, List -from astrbot.api.message_components import * +from astrbot.api.message_components import Image, Plain from astrbot.core.platform.astr_message_event import MessageSesion from .qqofficial_message_event import QQOfficialMessageEvent from ...register import register_platform_adapter +from astrbot.core.message.components import BaseMessageComponent + +# remove logger handler +for handler in logging.root.handlers[:]: + logging.root.removeHandler(handler) # QQ 机器人官方框架 -@register_platform_adapter("qqofficial", "QQ 机器人官方 API 适配器") class botClient(Client): def set_platform(self, platform: 'QQOfficialPlatformAdapter'): self.platform = platform @@ -52,7 +58,7 @@ class botClient(Client): abm.session_id, self.platform.client )) - +@register_platform_adapter("qq_official", "QQ 机器人官方 API 适配器") class QQOfficialPlatformAdapter(Platform): def __init__(self, platform_config: dict, platform_settings: dict, event_queue: asyncio.Queue) -> None: @@ -94,7 +100,7 @@ class QQOfficialPlatformAdapter(Platform): def meta(self) -> PlatformMetadata: return PlatformMetadata( - "qqofficial", + "qq_official", "QQ 机器人官方 API 适配器", ) @@ -105,7 +111,7 @@ class QQOfficialPlatformAdapter(Platform): abm.timestamp = int(time.time()) abm.raw_message = message abm.message_id = message.id - abm.tag = "qqofficial" + abm.tag = "qq_official" msg: List[BaseMessageComponent] = [] if isinstance(message, botpy.message.GroupMessage) or isinstance(message, botpy.message.C2CMessage): @@ -137,7 +143,7 @@ class QQOfficialPlatformAdapter(Platform): elif isinstance(message, botpy.message.Message) or isinstance(message, botpy.message.DirectMessage): try: abm.self_id = str(message.mentions[0].id) - except: + except BaseException as _: abm.self_id = "" plain_content = message.content.replace(