mirror of
https://github.com/tom-snow/docker-ComWechat.git
synced 2025-04-19 19:49:13 +08:00
feat: skip version check automatically
This commit is contained in:
parent
e2b33a3eef
commit
9f3a9f8c81
39
run.py
39
run.py
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/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:
|
class DockerWechatHook:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -17,7 +18,7 @@ class DockerWechatHook:
|
|||||||
COMWECHAT = os.environ['COMWECHAT']
|
COMWECHAT = os.environ['COMWECHAT']
|
||||||
# NOTE: 当 ComWeChatRobot 的仓库地址变动的话需要修改
|
# NOTE: 当 ComWeChatRobot 的仓库地址变动的话需要修改
|
||||||
if not COMWECHAT.startswith("https://github.com/ljc545w/ComWeChatRobot/releases/download/"):
|
if not COMWECHAT.startswith("https://github.com/ljc545w/ComWeChatRobot/releases/download/"):
|
||||||
print("你提供的地址不是 COMWECHAT 仓库的 Release 下载地址,程序将自动退出!")
|
print("你提供的地址不是 COMWECHAT 仓库的 Release 下载地址,程序将自动退出!", flush=True)
|
||||||
self.exit_container()
|
self.exit_container()
|
||||||
self.prepare = subprocess.run(['wget', COMWECHAT, '-O', 'comwechat.zip'])
|
self.prepare = subprocess.run(['wget', COMWECHAT, '-O', 'comwechat.zip'])
|
||||||
self.prepare = subprocess.run(['unzip', '-d', 'comwechat', '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'])
|
# self.wechat = subprocess.run(['wine','/home/user/.wine/drive_c/Program Files/Tencent/WeChat/WeChat.exe'])
|
||||||
|
|
||||||
def run_hook(self):
|
def run_hook(self):
|
||||||
print("等待 5 秒再 hook")
|
print("等待 5 秒再 hook", flush=True)
|
||||||
time.sleep(5)
|
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'])
|
# 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):
|
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:
|
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)
|
os.kill(self.wechat.pid, signal.SIGTERM)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
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)
|
os.kill(self.reg_hook.pid, signal.SIGTERM)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
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)
|
os.kill(self.vnc.pid, signal.SIGTERM)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_all_in_one(self):
|
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.prepare()
|
||||||
self.run_vnc()
|
self.run_vnc()
|
||||||
self.run_wechat()
|
self.run_wechat()
|
||||||
self.run_hook()
|
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__' :
|
if __name__ == '__main__' :
|
||||||
print('---All in one 微信 ComRobot 容器---')
|
print('---All in one 微信 ComRobot 容器---', flush=True)
|
||||||
hook = DockerWechatHook()
|
hook = DockerWechatHook()
|
||||||
hook.run_all_in_one()
|
hook.run_all_in_one()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user