🐛 修复可能发起多个连接的bug (#541)

* 修复可能发起多个连接的bug

* 🚨 `pre-commit-ci`修复格式错误

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
RBAmeto 2023-05-15 10:33:00 +08:00 committed by GitHub
parent dedaf0a65f
commit 9383755899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,15 +10,22 @@ from .base import sv, logger, hoshino_bot
from .models import Message, MessageReceive from .models import Message, MessageReceive
gsclient: Optional[GsClient] = None gsclient: Optional[GsClient] = None
gsconnecting = False
async def connect(): async def connect():
global gsclient global gsclient
try: global gsconnecting
gsclient = await GsClient().async_connect() if not gsconnecting:
await gsclient.start() gsconnecting = True
except ConnectionRefusedError: try:
logger.error('Core服务器连接失败...请稍后使用[启动core]命令启动...') 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): async def get_gs_msg(ev):