From 8f299585f5e35ff438bc64f19f99a58bc51c5139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuyi=E6=97=A0=E7=96=91?= <444835641@qq.com> Date: Sun, 26 Mar 2023 18:57:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20=E4=B8=BA=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E4=BD=93=E5=A2=9E=E5=8A=A0`bot=5Fself=5Fid`=E4=BB=A5=E9=80=82?= =?UTF-8?q?=E9=85=8D=E5=A4=9A=E8=B4=A6=E6=88=B7=20(#472)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GenshinUID/__init__.py | 2 ++ GenshinUID/client.py | 15 +++++++++++---- GenshinUID/models.py | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/GenshinUID/__init__.py b/GenshinUID/__init__.py index 6b9259ea..fd3a0021 100644 --- a/GenshinUID/__init__.py +++ b/GenshinUID/__init__.py @@ -27,6 +27,7 @@ async def get_gs_msg(ev): user_id = str(ev.user_id) msg_id = str(ev.message_id) group_id = str(ev.group_id) + self_id = str(ev.self_id) messages = ev.message message: List[Message] = [] msg_id = '' @@ -65,6 +66,7 @@ async def get_gs_msg(ev): user_type = 'group' if group_id else 'direct' msg = MessageReceive( bot_id=bot_id, + bot_self_id=self_id, user_type=sp_user_type if sp_user_type else user_type, group_id=group_id, user_id=user_id, diff --git a/GenshinUID/client.py b/GenshinUID/client.py index 4998eea3..261ac617 100644 --- a/GenshinUID/client.py +++ b/GenshinUID/client.py @@ -43,7 +43,10 @@ class GsClient: # 解析消息 if msg.bot_id == 'NoneBot2': continue + bot = hoshino_bot + # self_ids = hoshino.get_self_ids() + content = '' image: Optional[str] = None node = [] @@ -74,11 +77,14 @@ class GsClient: image, node, file, + msg.bot_self_id, msg.target_id, msg.target_type, ) except Exception as e: logger.error(e) + except RuntimeError: + pass except ConnectionClosedError: logger.warning(f'与[gsuid-core]断开连接! Bot_ID: {BOT_ID}') self.is_alive = False @@ -127,6 +133,7 @@ async def onebot_send( image: Optional[str], node: Optional[List[Dict]], file: Optional[str], + bot_self_id: Optional[str], target_id: Optional[str], target_type: Optional[str], ): @@ -156,14 +163,14 @@ async def onebot_send( del_file(path) else: if target_type == 'group': - await bot.call_action( - 'send_group_msg', + await bot.send_group_msg( + self_id=bot_self_id, group_id=target_id, message=result_msg, ) else: - await bot.call_action( - 'send_private_msg', + await bot.send_private_msg( + self_id=bot_self_id, user_id=target_id, message=result_msg, ) diff --git a/GenshinUID/models.py b/GenshinUID/models.py index dc312814..2c037d45 100644 --- a/GenshinUID/models.py +++ b/GenshinUID/models.py @@ -10,6 +10,7 @@ class Message(Struct): class MessageReceive(Struct): bot_id: str = 'Bot' + bot_self_id: str = '' msg_id: str = '' user_type: Literal['group', 'direct', 'channel', 'sub_channel'] = 'group' group_id: Optional[str] = None @@ -31,6 +32,7 @@ class MessageContent(Struct): class MessageSend(Struct): bot_id: str = 'Bot' + bot_self_id: str = '' msg_id: str = '' target_type: Optional[str] = None target_id: Optional[str] = None