-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (40 loc) · 1.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from flask import Flask
import threading
import time
from TangTangBot import *
status = ""
app = Flask(__name__)
@app.route('/bot', methods=['GET'])
def bot_info():
try:
print(bot.get_me())
return str(bot.get_me())
except:
return "无法获取bot信息,请检查api token"
def run_bot():
while True:
try:
bot.polling(none_stop=True)
except Exception as e:
time.sleep(10)
@app.route('/', methods=['GET'])
def index():
global status
if status=="":
t1 = threading.Thread(target=run_bot)
t1.start()
print(t1.is_alive())
status = t1
return "正在唤醒Bot", 200
else:
print(status.is_alive())
if status.is_alive() == True:
return "Bot 已经在运行"
elif status.is_alive() == False:
t1 = threading.Thread(target=run_bot)
t1.start()
print(t1.is_alive())
status=t1
return "重新唤醒Bot", 200
if __name__ == '__main__':
app.run(debug=True)