From 9f3a9f8c81962ec4ebc6e2259f2aec58abb2e5f5 Mon Sep 17 00:00:00 2001 From: jiz4oh Date: Wed, 12 Feb 2025 17:11:48 +0800 Subject: [PATCH] feat: skip version check automatically --- run.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/run.py b/run.py index 5176e14..6f7f49d 100644 --- a/run.py +++ b/run.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 -import subprocess, os, signal, datetime, time +import subprocess, os, signal, datetime, time, json, sys +version = os.environ.get('COMWECHAT_VERSION', '3.9.12.16') class DockerWechatHook: def __init__(self): @@ -17,7 +18,7 @@ class DockerWechatHook: COMWECHAT = os.environ['COMWECHAT'] # NOTE: 当 ComWeChatRobot 的仓库地址变动的话需要修改 if not COMWECHAT.startswith("https://github.com/ljc545w/ComWeChatRobot/releases/download/"): - print("你提供的地址不是 COMWECHAT 仓库的 Release 下载地址,程序将自动退出!") + print("你提供的地址不是 COMWECHAT 仓库的 Release 下载地址,程序将自动退出!", flush=True) self.exit_container() self.prepare = subprocess.run(['wget', COMWECHAT, '-O', 'comwechat.zip']) self.prepare = subprocess.run(['unzip', '-d', 'comwechat', 'comwechat.zip']) @@ -45,39 +46,53 @@ class DockerWechatHook: # self.wechat = subprocess.run(['wine','/home/user/.wine/drive_c/Program Files/Tencent/WeChat/WeChat.exe']) def run_hook(self): - print("等待 5 秒再 hook") + print("等待 5 秒再 hook", flush=True) time.sleep(5) - self.reg_hook = subprocess.run(['wine','/comwechat/http/WeChatHook.exe']) + self.reg_hook = subprocess.Popen(['wine','/comwechat/http/WeChatHook.exe']) # self.reg_hook = subprocess.run(['wine', 'explorer.exe']) + + def change_version(self): + time.sleep(5) + result = subprocess.run(['curl', '-X', 'POST', 'http://127.0.0.1:18888/api/?type=35', '-H', 'Content-Type: application/json', '-d', json.dumps({"path": "/comwechat/http/WeChatHook.exe", "version": version})], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if result.returncode != 0: + print(f"Curl command failed with error: {result.stderr.decode()}", flush=True) + print("版本修改失败", flush=True) + self.exit_container() + sys.exit(1) + else: + print("版本已经修改", flush=True) def exit_container(self): - print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 正在退出容器...') + print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 正在退出容器...', flush=True) try: - print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 退出微信...') + print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 退出微信...', flush=True) os.kill(self.wechat.pid, signal.SIGTERM) except: pass try: - print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 退出Hook程序...') + print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 退出Hook程序...', flush=True) os.kill(self.reg_hook.pid, signal.SIGTERM) except: pass try: - print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 退出VNC...') + print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 退出VNC...', flush=True) os.kill(self.vnc.pid, signal.SIGTERM) except: pass def run_all_in_one(self): - print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 启动容器中...') + print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 启动容器中...', flush=True) self.prepare() self.run_vnc() self.run_wechat() self.run_hook() - print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 感谢使用.') + self.change_version() + while True: + time.sleep(1) + print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+ ' 感谢使用.', flush=True) if __name__ == '__main__' : - print('---All in one 微信 ComRobot 容器---') + print('---All in one 微信 ComRobot 容器---', flush=True) hook = DockerWechatHook() - hook.run_all_in_one() \ No newline at end of file + hook.run_all_in_one()