From b0ac2d676c4ba147f2e17e68085353f6f16767dc Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Tue, 25 Apr 2023 20:48:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Replit=E5=B9=B3=E5=8F=B0=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 13 +++++++++++++ webapp_replit.py | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 webapp_replit.py diff --git a/main.py b/main.py index 7fd64b820..e9e9727e8 100644 --- a/main.py +++ b/main.py @@ -105,6 +105,19 @@ def get_platform(): if __name__ == "__main__": check_env() + + # 获取参数 + args = sys.argv + if len(args) > 1: + if args[1] == '-replit': + print("[System] 启动Replit Web保活服务...") + try: + from webapp_replit import keep_alive + keep_alive() + except BaseException as e: + print(e) + print(f"[System-err] Replit Web保活服务启动失败:{str(e)}") + bot_event = threading.Event() loop = asyncio.get_event_loop() main(loop, bot_event) \ No newline at end of file diff --git a/webapp_replit.py b/webapp_replit.py new file mode 100644 index 000000000..f406b47dc --- /dev/null +++ b/webapp_replit.py @@ -0,0 +1,23 @@ +from flask import Flask +from threading import Thread +import datetime + +app = Flask(__name__) + + +@app.route('/') +def main_func(): + content = "

QQChannelChatGPT Web APP

" + + content = "

" + "Online @ " + str(datetime.datetime.now()) + "

" + content = "

欢迎Star本项目!!!

" + return content + + +def run(): + app.run(host="0.0.0.0", port=8080) + + +def keep_alive(): + server = Thread(target=run) + server.start()