Skip to content

Commit

Permalink
0.11.32,内置AstralQsign
Browse files Browse the repository at this point in the history
Co-Authored-By: 仑质 <[email protected]>
  • Loading branch information
MetaLe0 and lunzhiPenxil committed Jun 1, 2024
1 parent cd72e48 commit 53a536c
Show file tree
Hide file tree
Showing 9 changed files with 566 additions and 186 deletions.
1 change: 1 addition & 0 deletions OlivOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
from .libBooter import libCWCBEXEModelAPI
from .libBooter import libOPQBotEXEModelAPI
from .libBooter import libNapCatEXEModelAPI
from .libBooter import libAstralQsignEXEModelAPI
from .nativeGUI import nativeWinUIAPI
from .nativeGUI import webviewUIAPI
from . import userModule
14 changes: 14 additions & 0 deletions OlivOS/core/L10N/L10NDataAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@
'libCWCBEXEModelAPI_0004': 'OlivOS libCWCBEXEModel failed: {0}\n{1}',
'libCWCBEXEModelAPI_0005': 'OlivOS libCWCBEXEModel server [{0}] is running',
'libCWCBEXEModelAPI_0006': 'OlivOS libCWCBEXEModel server [{0}] exited',
'libAstralQsignEXEModelAPI_0001': 'OlivOS libAstralQsignEXEModel server [{0}] can`t found target lib',
'libAstralQsignEXEModelAPI_0002': 'OlivOS libAstralQsignEXEModel server [{0}] will run under visiable mode',
'libAstralQsignEXEModelAPI_0003': 'OlivOS libAstralQsignEXEModel server [{0}] will retry in 10s...',
'libAstralQsignEXEModelAPI_0004': 'OlivOS libAstralQsignEXEModel failed: {0}\n{1}',
'libAstralQsignEXEModelAPI_0005': 'OlivOS libAstralQsignEXEModel server [{0}] is running',
'libAstralQsignEXEModelAPI_0006': 'OlivOS libAstralQsignEXEModel server [{0}] exited',
'libAstralQsignEXEModelAPI_0007': 'OlivOS libAstralQsignEXEModel server [{0}] is running on port [{1}]',
'bootAPI_0001': 'OlivOS model [{0}] will init',
'bootAPI_0002': 'OlivOS model [{0}] init',
'bootAPI_0003': 'OlivOS model [{0}] will try init',
Expand Down Expand Up @@ -207,6 +214,13 @@
'libCWCBEXEModelAPI_0004': 'OlivOS ComWeChatBotClient进程托管服务组件 错误: {0}\n{1}',
'libCWCBEXEModelAPI_0005': 'OlivOS ComWeChatBotClient进程托管服务组件 [{0}] 正在运作',
'libCWCBEXEModelAPI_0006': 'OlivOS ComWeChatBotClient进程托管服务组件 [{0}] 已经存在',
'libAstralQsignEXEModelAPI_0001': 'OlivOS libAstralQsignEXEModelAPI进程托管服务组件 [{0}] 无法找到库文件',
'libAstralQsignEXEModelAPI_0002': 'OlivOS libAstralQsignEXEModelAPI进程托管服务组件 [{0}] 将在前台模式下运行',
'libAstralQsignEXEModelAPI_0003': 'OlivOS libAstralQsignEXEModelAPI进程托管服务组件 [{0}] 将在10秒后重试...',
'libAstralQsignEXEModelAPI_0004': 'OlivOS libAstralQsignEXEModelAPI进程托管服务组件 错误: {0}\n{1}',
'libAstralQsignEXEModelAPI_0005': 'OlivOS libAstralQsignEXEModelAPI进程托管服务组件 [{0}] 正在运作',
'libAstralQsignEXEModelAPI_0006': 'OlivOS libAstralQsignEXEModelAPI进程托管服务组件 [{0}] 已经存在',
'libAstralQsignEXEModelAPI_0007': 'OlivOS libAstralQsignEXEModelAPI进程托管服务组件 [{0}] 正在运作于端口 [{1}]',
'bootAPI_0001': 'OlivOS 组件 [{0}] 即将初始化',
'bootAPI_0002': 'OlivOS 组件 [{0}] 初始化',
'bootAPI_0003': 'OlivOS 组件 [{0}] 即将尝试初始化',
Expand Down
22 changes: 20 additions & 2 deletions OlivOS/core/boot/bootAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,27 @@ def start(self):
'tmp_proc_mode': tmp_proc_mode
}
).start()
elif basic_conf_models_this['type'] == 'astralqsign_lib_exe_model':
if not OlivOS.libAstralQsignEXEModelAPI.isBotActive(plugin_bot_info_dict):
continue
if platform.system() == 'Windows':
threading.Thread(
target = OlivOS.libAstralQsignEXEModelAPI.startAstralQsignLibExeModel,
kwargs = {
'plugin_bot_info_dict': plugin_bot_info_dict,
'basic_conf_models_this': basic_conf_models_this,
'multiprocessing_dict': multiprocessing_dict,
'Proc_dict': Proc_dict,
'Proc_Proc_dict': Proc_Proc_dict,
'basic_conf_models': basic_conf_models,
'tmp_proc_mode': tmp_proc_mode
}
).start()
elif basic_conf_models_this['type'] == 'update_get':
threading.Thread(target=update_get_func,
args=(Proc_dict, basic_conf_models, basic_conf_models_this)).start()
threading.Thread(
target=update_get_func,
args=(Proc_dict, basic_conf_models, basic_conf_models_this)
).start()
elif basic_conf_models_this['type'] == 'update_replace':
OlivOS.updateAPI.OlivOSUpdateReplace(
logger_proc=Proc_dict[basic_conf_models_this['logger_proc']]
Expand Down
19 changes: 19 additions & 0 deletions OlivOS/core/boot/bootDataAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"OlivOS_account_config_save",
"OlivOS_account_config",
"OlivOS_nativeWinUIAPI",
"OlivOS_astralqsign_lib_exe_model",
"OlivOS_gocqhttp_lib_exe_model",
"OlivOS_walleq_lib_exe_model",
"OlivOS_cwcb_lib_exe_model",
Expand Down Expand Up @@ -75,6 +76,7 @@
"OlivOS_account_config_update"
],
"account_update": [
"OlivOS_astralqsign_lib_exe_model",
"OlivOS_gocqhttp_lib_exe_model",
"OlivOS_walleq_lib_exe_model",
"OlivOS_cwcb_lib_exe_model",
Expand All @@ -100,6 +102,7 @@
},
"type_event": {
"account_update": [
"astralqsign_lib_exe_model",
"gocqhttp_lib_exe_model",
"walleq_lib_exe_model",
"cwcb_lib_exe_model",
Expand Down Expand Up @@ -478,6 +481,7 @@
"tx_queue": "OlivOS_rx_queue",
"logger_proc": "OlivOS_logger",
"target_proc": "OlivOS_flask_post_rx",
"sub_target_proc": "OlivOS_astralqsign_lib_exe_model",
"control_queue": "OlivOS_control_queue",
"debug": False
},
Expand Down Expand Up @@ -533,6 +537,21 @@
"control_queue": "OlivOS_control_queue",
"debug": False
},
"OlivOS_astralqsign_lib_exe_model": {
"enable": True,
"name": "OlivOS_astralqsign_lib_exe_model",
"type": "astralqsign_lib_exe_model",
"tx_queue": "OlivOS_rx_queue",
"logger_proc": "OlivOS_logger",
"control_queue": "OlivOS_control_queue",
"debug": False,
"server": {
"auto": True,
"host": "0.0.0.0",
"port": 55011,
"token": "114514"
}
},
"OlivOS_webview_page": {
"enable": True,
"name": "OlivOS_webview_page",
Expand Down
25 changes: 17 additions & 8 deletions OlivOS/core/core/accountAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,23 @@ def accountFix(basic_conf_models, bot_info_dict, logger_proc):
res = {}
with free_port_selector() as g: # 在端口选择过程中使用上下文
for basic_conf_models_this in basic_conf_models:
if basic_conf_models[basic_conf_models_this]['type'] == 'post':
if basic_conf_models[basic_conf_models_this]['server']['auto'] == True:
basic_conf_models[basic_conf_models_this]['server']['host'] = '0.0.0.0'
if isInuse(
'127.0.0.1',
basic_conf_models[basic_conf_models_this]['server']['port']
):
basic_conf_models[basic_conf_models_this]['server']['port'] = g.get_free_port()
if basic_conf_models[basic_conf_models_this]['type'] == 'post' \
and basic_conf_models[basic_conf_models_this]['server']['auto'] is True:
basic_conf_models[basic_conf_models_this]['server']['host'] = '0.0.0.0'
if isInuse(
'127.0.0.1',
basic_conf_models[basic_conf_models_this]['server']['port']
):
basic_conf_models[basic_conf_models_this]['server']['port'] = g.get_free_port()
if platform.system() == 'Windows' \
and basic_conf_models[basic_conf_models_this]['type'] == 'astralqsign_lib_exe_model' \
and basic_conf_models[basic_conf_models_this]['server']['auto'] is True:
basic_conf_models[basic_conf_models_this]['server']['host'] = '0.0.0.0'
if isInuse(
'127.0.0.1',
basic_conf_models[basic_conf_models_this]['server']['port']
):
basic_conf_models[basic_conf_models_this]['server']['port'] = g.get_free_port()
for bot_info_dict_this in bot_info_dict:
Account_data_this = bot_info_dict[bot_info_dict_this]
if platform.system() == 'Windows':
Expand Down
4 changes: 2 additions & 2 deletions OlivOS/core/info/infoAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import OlivOS


OlivOS_Version = '0.11.31'
OlivOS_SVN = 151
OlivOS_Version = '0.11.32'
OlivOS_SVN = 152

# Compatible <= Plugin[compatible_svn] : Compatible
# OldCompatible <= Plugin[compatible_svn] < Compatible : OldCompatible Warn
Expand Down
217 changes: 217 additions & 0 deletions OlivOS/libBooter/libAstralQsignEXEModelAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
# -*- encoding: utf-8 -*-
'''
_______________________ ________________
__ __ \__ /____ _/_ | / /_ __ \_ ___/
_ / / /_ / __ / __ | / /_ / / /____ \
/ /_/ /_ /____/ / __ |/ / / /_/ /____/ /
\____/ /_____/___/ _____/ \____/ /____/
@File : OlivOS/libAstralQsignEXEModelAPI.py
@Author : MetaLeo元理
@Contact : [email protected]
@License : AGPL
@Copyright : (C) 2020-2024, OlivOS-Team
@Desc : None
'''

import subprocess
import time
import os
import traceback
import platform
import zipfile

import OlivOS

modelName = 'libAstralQsignEXEModelAPI'

resourceUrlPath = OlivOS.infoAPI.resourceUrlPath

gCheckList = [
'gocqhttp_show_Android_Phone',
'gocqhttp_show_Android_Pad'
]

def startAstralQsignLibExeModel(
plugin_bot_info_dict,
basic_conf_models_this,
multiprocessing_dict,
Proc_dict,
Proc_Proc_dict,
basic_conf_models,
tmp_proc_mode
):
if platform.system() == 'Windows':
flagActive = False
for bot_info_key in plugin_bot_info_dict:
if plugin_bot_info_dict[bot_info_key].platform['model'] in gCheckList:
flagActive = True
if flagActive:
releaseDir('./lib')
OlivOS.updateAPI.checkResouceFile(
logger_proc=Proc_dict[basic_conf_models_this['logger_proc']],
resouce_api=resourceUrlPath,
resouce_name='astral-qsign',
filePath='./lib/astral-qsign.zip',
filePathUpdate='./lib/astral-qsign.zip.tmp',
filePathFORCESKIP='./lib/FORCESKIP'
)
for bot_info_key in plugin_bot_info_dict:
if plugin_bot_info_dict[bot_info_key].platform['model'] in gCheckList:
tmp_Proc_name = basic_conf_models_this['name']
Proc_dict[tmp_Proc_name] = OlivOS.libAstralQsignEXEModelAPI.server(
Proc_name=tmp_Proc_name,
tx_queue=multiprocessing_dict[basic_conf_models_this['tx_queue']],
control_queue=multiprocessing_dict[basic_conf_models_this['control_queue']],
logger_proc=Proc_dict[basic_conf_models_this['logger_proc']],
server_data=basic_conf_models_this['server'],
debug_mode=False
)
Proc_Proc_dict[tmp_Proc_name] = Proc_dict[tmp_Proc_name].start_unity(tmp_proc_mode)

class server(OlivOS.API.Proc_templet):
def __init__(
self,
Proc_name,
scan_interval=0.001,
dead_interval=1,
rx_queue=None,
tx_queue=None,
control_queue=None,
logger_proc=None,
server_data=None,
debug_mode=False
):
OlivOS.API.Proc_templet.__init__(
self,
Proc_name=Proc_name,
Proc_type='astralqsign_lib_exe_model',
scan_interval=scan_interval,
dead_interval=dead_interval,
rx_queue=rx_queue,
tx_queue=tx_queue,
control_queue=control_queue,
logger_proc=logger_proc
)
self.Proc_config['debug_mode'] = debug_mode
self.server_data=server_data
self.flag_run = True

def run(self):
while self.flag_run:
self.sendLog(
2, 'OlivOS libAstralQsignEXEModel server [{0}] will run under visiable mode',
[self.Proc_name]
)
time.sleep(2)
releaseDir("./conf")
releaseDir("./conf/astral-qsign")
unzip('./lib/astral-qsign.zip', "./conf/astral-qsign")
tmp_env = dict(os.environ)
tmp_env['FORCE_TTY'] = ''
model_Proc = subprocess.Popen(
f".\\start.bat {self.server_data['port']}",
cwd='.\\conf\\astral-qsign',
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
creationflags=subprocess.CREATE_NEW_CONSOLE,
env=tmp_env
)
self.sendLog(
2, 'OlivOS libAstralQsignEXEModel server [{0}] is running on port [{1}]',
[self.Proc_name, str(self.server_data['port'])]
)
self.Proc_data['model_Proc'] = model_Proc
self.get_model_stdout(model_Proc)
# model_Proc.communicate(timeout = None)
self.log(3, OlivOS.L10NAPI.getTrans(
'OlivOS libAstralQsignEXEModel server [{0}] will retry in 10s...',
[self.Proc_name], modelName
))
self.Proc_data['model_Proc'] = None
time.sleep(8)

def get_model_stdout(self, model_Proc: subprocess.Popen):
for line in iter(model_Proc.stdout.readline, b''):
try:
log_data = ('%s' % line.decode('utf-8', errors='replace')).rstrip('\n').rstrip('\r')
self.log(2, log_data, [('AstralQsign', 'default')])
except Exception as e:
self.log(4, OlivOS.L10NAPI.getTrans('OlivOS libAstralQsignEXEModel failed: %s\n%s' % [
str(e),
traceback.format_exc()
],
modelName
))

def send_log_event(self, data):
self.sendControlEventSend('send', {
'target': {
'type': 'nativeWinUI'
},
'data': {
'action': 'AstralQsign',
'event': 'log',
'hash': self.Proc_data['bot_info_dict'].hash,
'data': data
}
}
)

def sendControlEventSend(self, action, data):
if self.Proc_info.control_queue is not None:
self.Proc_info.control_queue.put(
OlivOS.API.Control.packet(
action,
data
),
block=False
)

def sendLog(self, log_level:int, log_message:str, log_message_list:list):
self.log(
log_level,
OlivOS.L10NAPI.getTrans(
log_message,
log_message_list,
modelName
),
[('AstralQsign', 'default')]
)



def isBotActive(plugin_bot_info_dict:dict):
flag_need_enable = False
for bot_info_key in plugin_bot_info_dict:
if plugin_bot_info_dict[bot_info_key].platform['sdk'] == 'onebot' \
and plugin_bot_info_dict[bot_info_key].platform['platform'] == 'qq' \
and plugin_bot_info_dict[bot_info_key].platform['model'] in OlivOS.libAstralQsignEXEModelAPI.gCheckList \
and plugin_bot_info_dict[bot_info_key].extends.get('qsign-server-protocal', None) == 'AstralQsign':
flag_need_enable = True
return flag_need_enable

def releaseDir(dir_path):
if not os.path.exists(dir_path):
os.makedirs(dir_path)

def support_gbk(zip_file: zipfile.ZipFile):
name_to_info = zip_file.NameToInfo
# copy map first
for name, info in name_to_info.copy().items():
try:
real_name = name.encode('cp437').decode('gbk')
except:
real_name = name
if real_name != name:
info.filename = real_name
del name_to_info[name]
name_to_info[real_name] = info
return zip_file

def unzip(zip_file_path, target_dir):
with support_gbk(zipfile.ZipFile(zip_file_path, 'r', zipfile.ZIP_DEFLATED)) as zip_file:
zip_file = support_gbk(zip_file)
zip_file.extractall(target_dir)
Loading

0 comments on commit 53a536c

Please sign in to comment.