-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMessage.py
258 lines (224 loc) · 8.73 KB
/
Message.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import requests
import json
Token = ''
def WebSend(api_url, headers, data) -> dict:
response = requests.post(api_url, headers=headers, data=json.dumps(data))
return json.loads(response.text)
def ImageAPI(path: str) -> str:
Webhook = "https://chat-go.jwzhd.com/open-apis/v1/image/upload?token="
api_url = Webhook + Token
files=[
('image',open(path,'rb'))
]
response = requests.request("POST", api_url, files=files)
return response.json()
class Send:
def __init__(self):
Webhook = 'https://chat-go.jwzhd.com/open-apis/v1/bot/send?token='
self.api_url = Webhook + Token
self.headers = {"Content-Type": "application/json; charset=utf-8", }
def Text(self, recvId: str, recvType: str, text: str, buttons: list = [], parentId: str = None):
data = {
"recvId": recvId,
"recvType": recvType,
"contentType": "text",
"content": {
"text": text,
"buttons": [buttons]
}
}
if parentId != None:
data["parentId"] = parentId
return WebSend(self.api_url, self.headers, data)
def Markdown(self, recvId: str, recvType: str, markdown: str, buttons: list = [], parentId: str = None):
data = {
"recvId": recvId,
"recvType": recvType,
"contentType": "markdown",
"content": {
"text": markdown,
"buttons": [buttons]
}
}
if parentId != None:
data["parentId"] = parentId
return WebSend(self.api_url, self.headers, data)
def Image(self, recvId: str, recvType: str, imagePath: str, buttons: list = [], parentId: str = None):
data = {
"recvId": recvId,
"recvType": recvType,
"contentType": "image",
"content": {
"imageKey": ImageAPI(imagePath)["data"]["imageKey"],
"buttons": [buttons]
}
}
if parentId != None:
data["parentId"] = parentId
return WebSend(self.api_url, self.headers, data)
def File(self, recvId: str, recvType: str, fileName: str, fileUrl: str, buttons: list = [], parentId: str = None):
data = {
"recvId": recvId,
"recvType": recvType,
"contentType": "file",
"content": {
"fileName": fileName,
"fileUrl": fileUrl,
"buttons": [buttons]
}
}
if parentId != None:
data["parentId"] = parentId
return WebSend(self.api_url, self.headers, data)
class Edit:
def __init__(self):
Webhook = 'https://chat-go.jwzhd.com/open-apis/v1/bot/edit?token='
self.api_url = Webhook + Token
self.headers = {"Content-Type": "application/json; charset=utf-8", }
def Text(self, msgId: str, recvId: str, recvType: str, new_text: str, buttons: list = []):
data = {
"msgId": msgId,
"recvId": recvId,
"recvType": recvType,
"contentType": "text",
"content": {
"text": new_text,
"buttons": [buttons]
}
}
return WebSend(self.api_url, self.headers, data)
def Markdown(self, msgId: str, recvId: str, recvType: str, new_markdown: str, buttons: list = []):
data = {
"msgId": msgId,
"recvId": recvId,
"recvType": recvType,
"contentType": "markdown",
"content": {
"text": new_markdown,
"buttons": [buttons]
}
}
return WebSend(self.api_url, self.headers, data)
def Image(self, msgId: str, recvId: str, recvType: str, new_image_path: str, buttons: list = []):
data = {
"msgId": msgId,
"recvId": recvId,
"recvType": recvType,
"contentType": "image",
"content": {
"imageKey": ImageAPI(new_image_path)["data"]["imageKey"],
"buttons": [buttons]
}
}
return WebSend(self.api_url, self.headers, data)
def File(self, msgId: str, recvId: str, recvType: str, new_file_name: str, new_file_url: str, buttons: list = []):
data = {
"msgId": msgId,
"recvId": recvId,
"recvType": recvType,
"contentType": "file",
"content": {
"fileName": new_file_name,
"fileUrl": new_file_url,
"buttons": [buttons]
}
}
return WebSend(self.api_url, self.headers, data)
class Messages:
def __init__(self):
Webhook = 'https://chat-go.jwzhd.com/open-apis/v1/bot/messages?token='
self.api_url = Webhook + Token
self.headers = {"Content-Type": "application/json; charset=utf-8", }
def Before(self, chat_id: str, chat_type: str, before: int):
target_url = f"{self.api_url}&chat-id={chat_id}&chat-type={chat_type}&before={before}"
response = requests.get(target_url, headers=self.headers)
return json.loads(response.text)
def After(self, chat_id: str, chat_type: str, message_id: str, after: int):
target_url = f"{self.api_url}&chat-id={chat_id}&chat-type={chat_type}&message-id={message_id}&after={after - 1}"
response = requests.get(target_url, headers=self.headers)
return json.loads(response.text)
class Board:
def __init__(self):
Webhook = 'https://chat-go.jwzhd.com/open-apis/v1/bot/board?token='
self.api_url = Webhook + Token
self.headers = {"Content-Type": "application/json; charset=utf-8", }
def Text(self, recvId: str, recvType: str, text: str, expireTime: int = 0):
data = {
"recvId": recvId,
"recvType": recvType,
"contentType": "text",
"content": text,
}
if expireTime != 0:
data["expireTime"] = expireTime
return WebSend(self.api_url, self.headers, data)
def Markdown(self, recvId: str, recvType: str, markdown: str, expireTime: int = 0):
data = {
"recvId": recvId,
"recvType": recvType,
"contentType": "markdown",
"content": markdown,
}
if expireTime != 0:
data["expireTime"] = expireTime
return WebSend(self.api_url, self.headers, data)
def Html(self, recvId: str, recvType: str, html: str, expireTime: int = 0):
data = {
"recvId": recvId,
"recvType": recvType,
"contentType": "html",
"content": html,
}
if expireTime != 0:
data["expireTime"] = expireTime
return WebSend(self.api_url, self.headers, data)
def Dismiss(self, recvId: str, recvType: str):
data = {
"recvId": recvId,
"recvType": recvType,
}
api_url = f'https://chat-go.jwzhd.com/open-apis/v1/bot/board-dismiss?token={Token}'
return WebSend(api_url, self.headers, data)
class All:
def __init__(self):
Webhook = 'https://chat-go.jwzhd.com/open-apis/v1/bot/board-all?token='
self.api_url = Webhook + Token
self.headers = {"Content-Type": "application/json; charset=utf-8", }
def Text(self, text: str, expireTime: int = 0):
data = {
"contentType": "text",
"content": text,
}
if expireTime != 0:
data["expireTime"] = expireTime
return WebSend(self.api_url, self.headers, data)
def Markdown(self, markdown: str, expireTime: int = 0):
data = {
"contentType": "markdown",
"content": markdown,
}
if expireTime != 0:
data["expireTime"] = expireTime
return WebSend(self.api_url, self.headers, data)
def Html(self, html: str, expireTime: int = 0):
data = {
"contentType": "html",
"content": html,
}
if expireTime != 0:
data["expireTime"] = expireTime
return WebSend(self.api_url, self.headers, data)
def Dismiss(self):
api_url = f'https://chat-go.jwzhd.com/open-apis/v1/bot/board-all-dismiss?token={Token}'
response = requests.post(api_url, headers=self.headers)
return json.loads(response.text)
def Delete(msgId: str, chatId: str, chatType: str):
Webhook = 'https://chat-go.jwzhd.com/open-apis/v1/bot/recall?token='
api_url = Webhook + Token
headers = {"Content-Type": "application/json; charset=utf-8", }
data = {
"msgId": msgId,
"chatId": chatId,
"chatType": chatType
}
return WebSend(api_url, headers, data)