From 9383755899f12305512963327e5418125084f23b Mon Sep 17 00:00:00 2001 From: RBAmeto <46624927+RBAmeto@users.noreply.github.com> Date: Mon, 15 May 2023 10:33:00 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=8F=91=E8=B5=B7=E5=A4=9A=E4=B8=AA=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E7=9A=84bug=20(#541)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复可能发起多个连接的bug * 🚨 `pre-commit-ci`修复格式错误 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- GenshinUID/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/GenshinUID/__init__.py b/GenshinUID/__init__.py index 3cddc553..707034b8 100644 --- a/GenshinUID/__init__.py +++ b/GenshinUID/__init__.py @@ -10,15 +10,22 @@ from .base import sv, logger, hoshino_bot from .models import Message, MessageReceive gsclient: Optional[GsClient] = None +gsconnecting = False async def connect(): global gsclient - try: - gsclient = await GsClient().async_connect() - await gsclient.start() - except ConnectionRefusedError: - logger.error('Core服务器连接失败...请稍后使用[启动core]命令启动...') + global gsconnecting + if not gsconnecting: + gsconnecting = True + try: + gsclient = await GsClient().async_connect() + logger.info('[gsuid-core]: 发起一次连接') + await gsclient.start() + gsconnecting = False + except ConnectionRefusedError: + gsconnecting = False + logger.error('Core服务器连接失败...请稍后使用[启动core]命令启动...') async def get_gs_msg(ev): @@ -128,7 +135,7 @@ async def import_gacha_log_info(session: NoticeSession): msg_id = '' pm = 6 - + if 'message_type' in ev: if priv.check_priv(ev, priv.SUPERUSER): pm = 1