-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
53 lines (39 loc) · 1.34 KB
/
main.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
49
50
51
52
53
from flask import Flask, request
from qq_server import QQMessageBase, PrivateMessage, GroupMessage, MessageType
from qq_server import dict_to_obj, color_report, ReportType, sweeper
from qq_server import server_bot
from qq_server import Defaults
import yaml
from typing import Tuple
app = Flask(__name__)
@app.route('/', methods=["POST"])
def post_data():
raw_package: dict = request.get_json()
if 'message_type' not in raw_package:
return 'skip'
data_package: QQMessageBase = dict_to_obj(raw_package)
message_type = data_package.message_type
if sweeper.skip_resquest(data_package):
return 'skip'
if message_type == MessageType.Private:
# 私聊信息
server_bot.handle_private(data_package)
if message_type == MessageType.Group:
# 群聊信息
server_bot.handle_group(data_package)
sweeper.exit_handle(data_package)
return 'ok'
if __name__ == '__main__':
from gevent import pywsgi
go_cqhttp_config = Defaults.go_cqhttp_config
python_server_config = Defaults.python_server_config
server_bot.launch(
go_cqhttp_config_path=go_cqhttp_config,
python_config_path=python_server_config
)
server = pywsgi.WSGIServer(
listener=(server_bot.host, server_bot.port),
application=app,
log=None
)
server.serve_forever()