-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.py
More file actions
70 lines (62 loc) · 1.96 KB
/
Main.py
File metadata and controls
70 lines (62 loc) · 1.96 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from flask import Flask, request
from Function import Function as Fun
from Function import DebugConsole as DBC
from Function import GoCQHttpLog as GCQH
from threading import Thread
import os
from importlib import reload
from datetime import datetime as dt
app = Flask('Ginsakura\'s Bot Frame')
@app.route('/', methods=["POST"])
def PostData():##接收Json,传递给data
data = request.get_json()
# if not data["post_type"] == "meta_event":
# # print(data)
# messageData = Fun.MessageProcess(data)
# if data['post_type'] == 'message':
# statu = messageData.MessageBypass()
# elif data['post_type'] == 'notice':
# statu = messageData.NoticeBypass()
try:
if not data["post_type"] == "meta_event":
# print(data)
messageData = Fun.MessageProcess(data)
if data['post_type'] == 'message':
statu = messageData.MessageBypass()
elif data['post_type'] == 'notice':
statu = messageData.NoticeBypass()
elif data['post_type'] == '':
statu = messageData.RequestBypass()
if statu[0] == 'reload':
reload(Fun)
reload(DBC)
Fun.Send(gid=statu[1],msg='Reload Success.').Send()
elif statu == 'unknown':
with open('./error.log','a',encoding='utf8') as f:
f.write(f'{dt.now()} Unknown\n')
f.write(str(data)+'\n')
except Exception as e:
print(e)
print(data)
with open('./error.log','a',encoding='utf8') as f:
f.write(f'{dt.now()} {str(e)}\n')
f.write(str(data)+'\n')
return 'OK'
def HTTP_Server():
# 此处的 host和 port对应上面 yml文件的设置
#保证和我们在配置里填的一致
app.run(host='127.0.0.1', port=5710)
def thread_start():##多线程(其实没必要)
#Go_CQHttp = Thread(target=GCQH.CQhttp)
#Go_CQHttp.start()
#Go_CQHttp.join()
HttpServer = Thread(target=HTTP_Server)
HttpServer.start()
HttpServer.join()
# Debug_Console = Thread(target=DBC.DebugConsole)
# Debug_Console.start()
# Debug_Console.join()
if __name__ == '__main__':
os.system('color 02')
# thread_start()
HTTP_Server()