mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-05-12 06:55:58 +08:00
🎨 连接core
This commit is contained in:
parent
c686a3ac81
commit
c3e9ae8f61
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user