This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApi.go
494 lines (429 loc) · 15.1 KB
/
Api.go
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
package cqhttp_go_sdk
import (
"encoding/json"
"io/ioutil"
"net/http"
"strings"
)
func Api(url string, token string) API {
return API{url, token}
}
type API struct {
url string
token string
}
func (api *API) post(path string, data map[string]interface{}) (map[string]interface{}, error) {
client := &http.Client{}
jo, _ := json.Marshal(data)
request, err := http.NewRequest("POST", api.url+path, strings.NewReader(string(jo)))
if err != nil {
panic(err)
}
request.Header.Set("Authorization", "Token "+api.token)
request.Header.Set("Content-Type", "application/json")
rb, err := client.Do(request)
defer rb.Body.Close()
if err != nil {
panic(err)
}
buffer, err := ioutil.ReadAll(rb.Body)
rd := map[string]interface{}{}
json.Unmarshal(buffer, &rd)
return rd, err
}
func (api *API) concurrentPost(path string, data map[string]interface{}, c chan<- map[string]interface{}) {
m, err := api.post(path, data)
m["error"] = err
c <- m
}
func (api *API) SendPrivateMsg(user_id float64, message string, auto_escape bool) (map[string]interface{}, error) {
return api.post("/send_private_msg", map[string]interface{}{
"user_id": user_id,
"message": message,
"auto_escape": auto_escape,
})
}
func (api *API) ConcurrentSendPrivateMsg(user_id float64, message string, auto_escape bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/send_private_msg", map[string]interface{}{
"user_id": user_id,
"message": message,
"auto_escape": auto_escape,
}, c)
return c
}
func (api *API) SendGroupMsg(group_id float64, message string, auto_escape bool) (map[string]interface{}, error) {
return api.post("/send_group_msg", map[string]interface{}{
"group_id": group_id,
"message": message,
"auto_escape": auto_escape,
})
}
func (api *API) ConcurrentSendGroupMsg(group_id float64, message string, auto_escape bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/send_group_msg", map[string]interface{}{
"group_id": group_id,
"message": message,
"auto_escape": auto_escape,
}, c)
return c
}
func (api *API) SendDiscussMsg(discuss_id float64, message string, auto_escape bool) (map[string]interface{}, error) {
return api.post("/send_discuss_msg", map[string]interface{}{
"discuss_id": discuss_id,
"message": message,
"auto_escape": auto_escape,
})
}
func (api *API) ConcurrentSendDiscussMsg(discuss_id float64, message string, auto_escape bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/send_discuss_msg", map[string]interface{}{
"discuss_id": discuss_id,
"message": message,
"auto_escape": auto_escape,
}, c)
return c
}
func (api *API) DeleteMsg(message_id float64) (map[string]interface{}, error) {
return api.post("/delete_msg", map[string]interface{}{
"message_id": message_id,
})
}
func (api *API) ConcurrentDeleteMsg(message_id float64) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/delete_msg", map[string]interface{}{
"message_id": message_id,
}, c)
return c
}
func (api *API) SendLike(user_id float64, times int) (map[string]interface{}, error) {
return api.post("/send_like", map[string]interface{}{
"user_id": user_id,
"times": times,
})
}
func (api *API) ConcurrentSendLike(user_id float64, times int) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/send_like", map[string]interface{}{
"user_id": user_id,
"times": times,
}, c)
return c
}
func (api *API) SetGroupKick(group_id float64, user_id float64, reject_add_request bool) (map[string]interface{}, error) {
return api.post("/set_group_kick", map[string]interface{}{
"group_id": group_id,
"user_id": user_id,
"reject_add_request": reject_add_request,
})
}
func (api *API) ConcurrentSetGroupKick(group_id float64, user_id float64, reject_add_request bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_kick", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"reject_add_request": reject_add_request,
}, c)
return c
}
func (api *API) SetGroupBan(group_id float64, user_id float64, duration int) (map[string]interface{}, error) {
return api.post("/set_group_ban", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"duration": duration,
})
}
func (api *API) ConcurrentSetGroupBan(group_id float64, user_id float64, duration int) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_ban", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"duration": duration,
}, c)
return c
}
func (api *API) SetGroupAnonymousBan(group_id float64, flag string, duration int) (map[string]interface{}, error) {
return api.post("/set_group_anonymous_ban", map[string]interface{}{
"group_id": group_id,
"flag": flag,
"duration": duration,
})
}
func (api *API) ConcurrentSetGroupAnonymousBan(group_id float64, flag string, duration int) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_anonymous_ban", map[string]interface{}{
"group_id": group_id,
"flag": flag,
"duration": duration,
}, c)
return c
}
func (api *API) SetGroupWholeBan(group_id float64, enable bool) (map[string]interface{}, error) {
return api.post("/set_group_whole_ban", map[string]interface{}{
"group_id": group_id,
"enable": enable,
})
}
func (api *API) ConcurrentSetGroupWholeBan(group_id float64, enable bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_whole_ban", map[string]interface{}{
"group_id": group_id,
"enable": enable,
}, c)
return c
}
func (api *API) SetGroupAdmin(group_id float64, user_id float64, enable bool) (map[string]interface{}, error) {
return api.post("/set_group_admin", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"enable": enable,
})
}
func (api *API) ConcurrentSetGroupAdmin(group_id float64, user_id float64, enable bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_admin", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"enable": enable,
}, c)
return c
}
func (api *API) SetGroupAnonymous(group_id float64, enable bool) (map[string]interface{}, error) {
return api.post("/set_group_anonymous", map[string]interface{}{
"group_id": group_id,
"enable": enable,
})
}
func (api *API) ConcurrentSetGroupAnonymous(group_id float64, enable bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_anonymous", map[string]interface{}{
"group_id": group_id,
"enable": enable,
}, c)
return c
}
func (api *API) SetGroupCard(group_id float64, user_id float64, card string) (map[string]interface{}, error) {
return api.post("/set_group_card", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"card": card,
})
}
func (api *API) ConcurrentSetGroupCard(group_id float64, user_id float64, card string) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_card", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"card": card,
}, c)
return c
}
func (api *API) SetGroupLeave(group_id float64, is_dismiss bool) (map[string]interface{}, error) {
return api.post("/set_group_leave", map[string]interface{}{
"group_id": group_id,
"is_dismiss": is_dismiss,
})
}
func (api *API) ConcurrentSetGroupLeave(group_id float64, is_dismiss bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_leave", map[string]interface{}{
"group_id": group_id,
"is_dismiss": is_dismiss,
}, c)
return c
}
func (api *API) SetGroupSpecialTitle(group_id float64, user_id float64, special_title string) (map[string]interface{}, error) {
return api.post("/set_group_special_title", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"special_title": special_title,
})
}
func (api *API) ConcurrentSetGroupSpecialTitle(group_id float64, user_id float64, special_title string) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_special_title", map[string]interface{}{
"user_id": user_id,
"group_id": group_id,
"special_title": special_title,
}, c)
return c
}
func (api *API) SetDiscussLeave(discuss_id float64) (map[string]interface{}, error) {
return api.post("/set_discuss_leave", map[string]interface{}{
"discuss_id": discuss_id,
})
}
func (api *API) ConcurrentSetDiscussLeave(discuss_id float64) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_discuss_leave", map[string]interface{}{
"discuss_id": discuss_id,
}, c)
return c
}
func (api *API) SetFriendAddRequest(flag string, approve bool, remark string) (map[string]interface{}, error) {
return api.post("/set_friend_add_request", map[string]interface{}{
"flag": flag,
"approve": approve,
"remark": remark,
})
}
func (api *API) ConcurrentSetFriendAddRequest(flag string, approve bool, remark string) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_friend_add_request", map[string]interface{}{
"flag": flag,
"approve": approve,
"remark": remark,
}, c)
return c
}
func (api *API) SetGroupAddRequest(flag string, _type string, approve bool, reason string) (map[string]interface{}, error) {
return api.post("/set_group_add_request", map[string]interface{}{
"flag": flag,
"type": _type,
"approve": approve,
"reason": reason,
})
}
func (api *API) ConcurrentSetGroupAddRequest(flag string, _type string, approve bool, reason string) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_group_add_request", map[string]interface{}{
"flag": flag,
"type": _type,
"approve": approve,
"reason": reason,
}, c)
return c
}
func (api *API) GetLoginInfo() (map[string]interface{}, error) {
return api.post("/get_login_info", map[string]interface{}{})
}
func (api *API) ConcurrentGetLoginInfo() chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_login_info", map[string]interface{}{}, c)
return c
}
func (api *API) GetStrangerInfo(user_id int, no_cache bool) (map[string]interface{}, error) {
return api.post("/get_stranger_info", map[string]interface{}{
"user_id": user_id,
"no_cache": no_cache,
})
}
func (api *API) ConcurrentGetStrangerInfo(user_id float64, no_cache bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_stranger_info", map[string]interface{}{
"user_id": user_id,
"no_cache": no_cache,
}, c)
return c
}
func (api *API) GetGroupList() (map[string]interface{}, error) {
return api.post("/get_group_list", map[string]interface{}{})
}
func (api *API) ConcurrentGetGroupList() chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_group_list", map[string]interface{}{}, c)
return c
}
func (api *API) GetGroupMemberInfo(group_id float64, user_id float64, no_cache bool) (map[string]interface{}, error) {
return api.post("/get_group_member_info", map[string]interface{}{
"group_id": group_id,
"user_id": user_id,
"no_cache": no_cache,
})
}
func (api *API) ConcurrentGetGroupMemberInfo(group_id float64, user_id float64, no_cache bool) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_group_member_info", map[string]interface{}{
"group_id": group_id,
"user_id": user_id,
"no_cache": no_cache,
}, c)
return c
}
func (api *API) GetGroupMemberList(group_id float64) (map[string]interface{}, error) {
return api.post("/get_group_member_list", map[string]interface{}{
"group_id": group_id,
})
}
func (api *API) ConcurrentGetGroupMemberList(group_id float64) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_group_member_list", map[string]interface{}{
"group_id": group_id,
}, c)
return c
}
func (api *API) GetCookies() (map[string]interface{}, error) {
return api.post("/get_cookies", map[string]interface{}{})
}
func (api *API) ConcurrentGetCookies() chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_cookies", map[string]interface{}{}, c)
return c
}
func (api *API) GetCsrfToken() (map[string]interface{}, error) {
return api.post("/get_csrf_token", map[string]interface{}{})
}
func (api *API) ConcurrentGetCsrfToken() chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_csrf_token", map[string]interface{}{}, c)
return c
}
func (api *API) GetRecord(file string, out_format string) (map[string]interface{}, error) {
return api.post("/get_record", map[string]interface{}{
"file": file,
"out_format": out_format,
})
}
func (api *API) ConcurrentGetRecord(file string, out_format string) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_record", map[string]interface{}{
"file": file,
"out_format": out_format,
}, c)
return c
}
func (api *API) GetStatus() (map[string]interface{}, error) {
return api.post("/get_status", map[string]interface{}{})
}
func (api *API) ConcurrentGetStatus() chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_status", map[string]interface{}{}, c)
return c
}
func (api *API) GetVersionInfo() (map[string]interface{}, error) {
return api.post("/get_version_info", map[string]interface{}{})
}
func (api *API) ConcurrentGetVersionInfo() chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/get_version_info", map[string]interface{}{}, c)
return c
}
func (api *API) SetRestartPlugin() (map[string]interface{}, error) {
return api.post("/set_restart_plugin", map[string]interface{}{})
}
func (api *API) ConcurrentSetRestartPlugin() chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/set_restart_plugin", map[string]interface{}{}, c)
return c
}
func (api *API) CleanDataDir(data_dir string) (map[string]interface{}, error) {
return api.post("/clean_data_dir", map[string]interface{}{
"data_dir": data_dir,
})
}
func (api *API) ConcurrentCleanDataDir(data_dir string) chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/clean_data_dir", map[string]interface{}{
"data_dir": data_dir,
}, c)
return c
}
//试验性接口
func (api *API) GetFriendList() (map[string]interface{}, error) {
return api.post("/_get_friend_list", map[string]interface{}{})
}
func (api *API) ConcurrentGetFriendList() chan map[string]interface{} {
c := make(chan map[string]interface{}, 1)
go api.concurrentPost("/_get_friend_list", map[string]interface{}{}, c)
return c
}