From c3e9ae8f61f903ab75dc5eb266e3b6d6d1c0139a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wuyi=E6=97=A0=E7=96=91?= <444835641@qq.com> Date: Sat, 11 Mar 2023 22:52:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20`=E8=BF=9E=E6=8E=A5core`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GenshinUID/__init__.py | 10 ++++++---- GenshinUID/client.py | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/GenshinUID/__init__.py b/GenshinUID/__init__.py index 85928bd6..61a1e409 100644 --- a/GenshinUID/__init__.py +++ b/GenshinUID/__init__.py @@ -13,14 +13,16 @@ from .models import Message, MessageReceive get_message = on_message(priority=999) install_core = on_fullmatch('gs一键安装', permission=SUPERUSER, block=True) -connect_core = on_fullmatch('连接core', permission=SUPERUSER, block=True) +connect_core = on_fullmatch( + ('连接core', '链接core'), permission=SUPERUSER, block=True +) driver = get_driver() gsclient: Optional[GsClient] = None @get_message.handle() async def send_char_adv(bot: Bot, ev: Event): - if gsclient is None: + if gsclient is None or not gsclient.is_alive: return await connect() # 通用字段获取 @@ -105,8 +107,8 @@ async def send_install_msg(matcher: Matcher): @connect_core.handle() async def send_start_msg(matcher: Matcher): - await start_client() - await matcher.send('链接成功!...') + await connect() + await matcher.send('链接成功!') @driver.on_bot_connect diff --git a/GenshinUID/client.py b/GenshinUID/client.py index 22cc4f98..20b9cf59 100644 --- a/GenshinUID/client.py +++ b/GenshinUID/client.py @@ -34,6 +34,7 @@ class GsClient: cls, IP: str = 'localhost', PORT: Union[str, int] = '8765' ): self = GsClient() + cls.is_alive = True cls.ws_url = f'ws://{IP}:{PORT}/ws/{BOT_ID}' logger.info(f'Bot_ID: {BOT_ID}连接至[gsuid-core]: {self.ws_url}...') cls.ws = await websockets.client.connect(cls.ws_url, max_size=2**26) @@ -109,6 +110,7 @@ class GsClient: logger.error(e) except ConnectionClosedError: logger.warning(f'与[gsuid-core]断开连接! Bot_ID: {BOT_ID}') + self.is_alive = False async def _input(self, msg: MessageReceive): await self.msg_list.put(msg)