diff --git a/GenshinUID/__init__.py b/GenshinUID/__init__.py index 720e9a5c..7ae92278 100644 --- a/GenshinUID/__init__.py +++ b/GenshinUID/__init__.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from nonebot.log import logger from nonebot.matcher import Matcher @@ -14,7 +14,7 @@ get_message = on_message(priority=999) install_core = on_fullmatch('gs一键安装', permission=SUPERUSER, block=True) start_core = on_fullmatch('启动core', permission=SUPERUSER, block=True) driver = get_driver() -gsclient: GsClient +gsclient: Optional[GsClient] = None @get_message.handle() @@ -36,14 +36,14 @@ async def send_char_adv(ev: Event): return msg = MessageReceive( bot_id=bot_id, - user_type='group' if group_id else 'user', + user_type='group' if group_id else 'direct', group_id=group_id, user_id=user_id, content=message, ) if gsclient is None: - await start_client() - logger.info(f'【发送】[gsuid-core]: {msg}') + return await start_client() + logger.info(f'【发送】[gsuid-core]: {msg.bot_id}') await gsclient._input(msg) @@ -55,11 +55,16 @@ async def send_install_msg(matcher: Matcher): @start_core.handle() async def send_start_msg(matcher: Matcher): - await matcher.send(await start()) + await start() + await start_client() + await matcher.send('启动完成...') @driver.on_bot_connect async def start_client(): global gsclient - gsclient = await GsClient().async_connect() - await gsclient.start() + try: + gsclient = await GsClient().async_connect() + await gsclient.start() + except ConnectionRefusedError: + logger.error('Core服务器连接失败...请稍后使用[启动core]命令启动...') diff --git a/GenshinUID/client.py b/GenshinUID/client.py index c365885b..73a965a8 100644 --- a/GenshinUID/client.py +++ b/GenshinUID/client.py @@ -1,5 +1,4 @@ import asyncio -from base64 import b64encode from typing import Union, Optional import websockets.client @@ -51,9 +50,7 @@ class GsClient: # 根据bot_id字段发送消息 if msg.bot_id == 'onebot': result_image = ( - f'[CQ:image,file=base64://{b64encode(image).decode()}]' - if image - else '' + f'[CQ:image,file=base64://{image}]' if image else '' ) result_msg = content + result_image if msg.target_type == 'group':