-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathServer.py
152 lines (125 loc) · 4.31 KB
/
Server.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from flask import Flask, request, jsonify
import json
app = Flask(__name__)
NormalFuncList = []
CommandFuncList = []
BotFollowedFuncList = []
BotUnFollowedFuncList = []
GroupJoinFuncList = []
GroupLeaveFuncList = []
BotSettingsFuncList = []
ButtonClickFuncList = []
AllTypeFuncList = []
class Message:
class Normal:
def __init__(self, func) -> None:
global NormalFuncList
self.func = func
NormalFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
class Command:
def __init__(self, func) -> None:
global CommandFuncList
self.func = func
CommandFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
class BotFollowed:
def __init__(self, func) -> None:
global BotFollowedFuncList
self.func = func
BotFollowedFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
class BotUnFollowed:
def __init__(self, func) -> None:
global BotUnFollowedFuncList
self.func = func
BotUnFollowedFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
class BotSettings:
def __init__(self, func) -> None:
global BotSettingsFuncList
self.func = func
BotSettingsFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
class GroupJoin:
def __init__(self, func) -> None:
global GroupJoinFuncList
self.func = func
GroupJoinFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
class GroupLeave:
def __init__(self, func) -> None:
global GroupLeaveFuncList
self.func = func
GroupLeaveFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
class ButtonClick:
def __init__(self, func) -> None:
global ButtonClickFuncList
self.func = func
ButtonClickFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
class AllType:
def __init__(self, func) -> None:
global AllTypeFuncList
self.func = func
AllTypeFuncList.append(func)
def __call__(self, *args, **kwds):
rv = self.func(*args, **kwds)
return rv
@app.route('/', methods=['POST'])
def RecvMsg():
data = request.json
if data['header']['eventType'] == "message.receive.normal":
for func in NormalFuncList:
func(data=data['event'])
if data['header']['eventType'] == "message.receive.instruction":
for func in CommandFuncList:
func(data=data['event'])
if data['header']['eventType'] == "bot.followed":
for func in BotFollowedFuncList:
func(data=data['event'])
if data['header']['eventType'] == "bot.unfollowed":
for func in BotUnFollowedFuncList:
func(data=data['event'])
if data['header']['eventType'] == "bot.setting":
for func in BotSettingsFuncList:
func(data=data['event'])
if data['header']['eventType'] == "group.join":
for func in GroupJoinFuncList:
func(data=data['event'])
if data['header']['eventType'] == "group.leave":
for func in GroupLeaveFuncList:
func(data=data['event'])
if data['header']['eventType'] == "button.report.inline":
for func in ButtonClickFuncList:
func(data=data['event'])
if AllTypeFuncList != []:
for func in AllTypeFuncList:
func(data=data['event'])
with open("RecvMsg.json", "w", encoding="utf-8") as RecvMsg:
json.dump(data, RecvMsg, ensure_ascii=False, indent=4)
return jsonify(data)
def Start(host: str, port: int, debug: bool = False):
app.run(
host=host,
port=port,
debug=debug,
threaded=True
)