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)