From 7736c1c9bd452c57372db60461d33a2871004a7c Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 15 Mar 2024 13:44:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20QQ=E6=9C=BA=E5=99=A8=E4=BA=BA=E5=AE=98?= =?UTF-8?q?=E6=96=B9API=20=E6=94=AF=E6=8C=81=E5=8F=AF=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=8E=A5=E6=94=B6Q=E7=BE=A4=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/dashboard/helper.py | 8 ++++++++ model/platform/qq_official.py | 18 ++++++++---------- util/cmd_config.py | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/addons/dashboard/helper.py b/addons/dashboard/helper.py index e28069c86..9f3abbd9f 100644 --- a/addons/dashboard/helper.py +++ b/addons/dashboard/helper.py @@ -100,6 +100,14 @@ class DashBoardHelper(): value=config['direct_message_mode'], path="direct_message_mode", ), + DashBoardConfig( + config_type="item", + val_type="bool", + name="是否接收QQ群消息", + description="需要机器人有相应的群消息接收权限。在 q.qq.com 上查看。", + value=config['qqofficial_enable_group_message'], + path="qqofficial_enable_group_message", + ), ] ) qq_gocq_platform_group = DashBoardConfig( diff --git a/model/platform/qq_official.py b/model/platform/qq_official.py index bc417b42b..fd944d5ad 100644 --- a/model/platform/qq_official.py +++ b/model/platform/qq_official.py @@ -56,26 +56,24 @@ class QQOfficial(Platform): self.secret = cfg['qqbot_secret'] self.unique_session = cfg['uniqueSessionMode'] self.logger: gu.Logger = global_object.logger + qq_group = cfg['qqofficial_enable_group_message'] - try: + if qq_group: self.intents = botpy.Intents( public_messages=True, public_guild_messages=True, direct_message=cfg['direct_message_mode'] ) - self.client = botClient( - intents=self.intents, - bot_log=False - ) - except BaseException: + else: self.intents = botpy.Intents( public_guild_messages=True, direct_message=cfg['direct_message_mode'] ) - self.client = botClient( - intents=self.intents, - bot_log=False - ) + self.client = botClient( + intents=self.intents, + bot_log=False + ) + self.client.set_platform(self) def run(self): diff --git a/util/cmd_config.py b/util/cmd_config.py index 688335e75..7aabaf3b1 100644 --- a/util/cmd_config.py +++ b/util/cmd_config.py @@ -102,6 +102,7 @@ def init_astrbot_config_items(): cc.init_attributes("other_admins", []) cc.init_attributes("CHATGPT_BASE_URL", "") cc.init_attributes("qqbot_secret", "") + cc.init_attributes("qqofficial_enable_group_message", False) cc.init_attributes("admin_qq", "") cc.init_attributes("nick_qq", ["!", "!", "ai"]) cc.init_attributes("admin_qqchan", "")