This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathconfigs.go
386 lines (307 loc) · 9.56 KB
/
configs.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
package qqbotapi
import (
"net/url"
"strconv"
"time"
)
// Chattable is any config type that can be sent.
type Chattable interface {
values() (url.Values, error)
method() string
}
// BaseChat is base type for all chat config types.
type BaseChat struct {
ChatID int64 // required
ChatType string
}
// values returns url.Values representation of BaseChat.
func (chat *BaseChat) values() (url.Values, error) {
v := url.Values{}
v.Add("message_type", chat.ChatType)
switch chat.ChatType {
case "private":
v.Add("user_id", strconv.FormatInt(chat.ChatID, 10))
case "group":
v.Add("group_id", strconv.FormatInt(chat.ChatID, 10))
case "discuss":
v.Add("discuss_id", strconv.FormatInt(chat.ChatID, 10))
}
return v, nil
}
// MessageConfig contains information about a SendMessage request.
type MessageConfig struct {
BaseChat
Text string
AutoEscape bool
}
// values returns a url.Values representation of MessageConfig.
func (config MessageConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("message", config.Text)
v.Add("auto_escape", strconv.FormatBool(config.AutoEscape))
return v, nil
}
// method returns CQ HTTP API method name for sending message.
func (config MessageConfig) method() string {
return "send_msg"
}
// DeleteMessageConfig contains information of a message in a chat to delete.
type DeleteMessageConfig struct {
MessageID int64
}
// method returns CQ HTTP API method name for deleting message.
func (config DeleteMessageConfig) method() string {
return "delete_msg"
}
// values returns url.Values representation of DeleteMessageConfig.
func (config DeleteMessageConfig) values() (url.Values, error) {
v := url.Values{}
v.Add("message_id", strconv.FormatInt(config.MessageID, 10))
return v, nil
}
// LikeConfig contains information of a like (displayed on personal profile page) to send.
type LikeConfig struct {
UserID int64
Times int
}
// method returns CQ HTTP API method name for sending like.
func (config LikeConfig) method() string {
return "send_like"
}
// values returns url.Values representation of LikeConfig.
func (config LikeConfig) values() (url.Values, error) {
v := url.Values{}
v.Add("user_id", strconv.FormatInt(config.UserID, 10))
v.Add("times", strconv.Itoa(config.Times))
return v, nil
}
// ChatMemberConfig contains information about a user in a chat for use
// with administrative functions such as kicking or unbanning a user.
type ChatMemberConfig struct {
GroupID int64
UserID int64
AnonymousFlag string
}
// values returns url.Values representation of ChatMemberConfig.
func (config ChatMemberConfig) values() (url.Values, error) {
v := url.Values{}
v.Add("group_id", strconv.FormatInt(config.GroupID, 10))
v.Add("user_id", strconv.FormatInt(config.UserID, 10))
v.Add("flag", config.AnonymousFlag)
return v, nil
}
// KickChatMemberConfig contains extra fields to kick user.
type KickChatMemberConfig struct {
ChatMemberConfig
RejectAddRequest bool
}
// method returns CQ HTTP API method name for kicking user.
func (config KickChatMemberConfig) method() string {
return "set_group_kick"
}
// values returns url.Values representation of KickChatMemberConfig.
func (config KickChatMemberConfig) values() (url.Values, error) {
v, err := config.ChatMemberConfig.values()
if err != nil {
return v, err
}
v.Add("reject_add_request", strconv.FormatBool(config.RejectAddRequest))
return v, nil
}
// RestrictChatMemberConfig contains fields to restrict members of chat.
type RestrictChatMemberConfig struct {
ChatMemberConfig
Duration time.Duration
}
// method returns CQ HTTP API method name for restricting user.
func (config RestrictChatMemberConfig) method() string {
if config.AnonymousFlag != "" {
return "set_group_anonymous_ban"
}
return "set_group_ban"
}
// values returns url.Values representation of RestrictChatMemberConfig.
func (config RestrictChatMemberConfig) values() (url.Values, error) {
v, err := config.ChatMemberConfig.values()
if err != nil {
return v, err
}
v.Add("duration", strconv.FormatFloat(config.Duration.Seconds(), 'f', -1, 64))
return v, nil
}
// PromoteChatMemberConfig contains fields to promote members of chat.
type PromoteChatMemberConfig struct {
ChatMemberConfig
Enable bool
}
// method returns CQ HTTP API method name for promoting user.
func (config PromoteChatMemberConfig) method() string {
return "set_group_admin"
}
// values returns url.Values representation of PromoteChatMemberConfig.
func (config PromoteChatMemberConfig) values() (url.Values, error) {
v, err := config.ChatMemberConfig.values()
if err != nil {
return v, err
}
v.Add("enable", strconv.FormatBool(config.Enable))
return v, nil
}
// SetChatMemberCardConfig contains fields to set members's 群名片.
type SetChatMemberCardConfig struct {
ChatMemberConfig
Card string
}
// method returns CQ HTTP API method name for setting card.
func (config SetChatMemberCardConfig) method() string {
return "set_group_card"
}
// values returns url.Values representation of SetChatMemberCardConfig.
func (config SetChatMemberCardConfig) values() (url.Values, error) {
v, err := config.ChatMemberConfig.values()
if err != nil {
return v, err
}
v.Add("card", config.Card)
return v, nil
}
// SetChatMemberTitleConfig contains fields to set members's 专属头衔.
type SetChatMemberTitleConfig struct {
ChatMemberConfig
SpecialTitle string
Duration time.Duration
}
// method returns CQ HTTP API method name for setting title.
func (config SetChatMemberTitleConfig) method() string {
return "set_group_card"
}
// values returns url.Values representation of SetChatMemberTitleConfig.
func (config SetChatMemberTitleConfig) values() (url.Values, error) {
v, err := config.ChatMemberConfig.values()
if err != nil {
return v, err
}
v.Add("special_title", config.SpecialTitle)
v.Add("duration", strconv.FormatFloat(config.Duration.Seconds(), 'f', -1, 64))
return v, nil
}
// GroupControlConfig contains fields as a configuration of a group.
type GroupControlConfig struct {
GroupID int64
Enable bool
}
// values returns url.Values representation of GroupControlConfig.
func (config GroupControlConfig) values() (url.Values, error) {
v := url.Values{}
v.Add("group_id", strconv.FormatInt(config.GroupID, 10))
v.Add("enable", strconv.FormatBool(config.Enable))
return v, nil
}
// RestrictAllChatMembersConfig contains fields to restrict all chat members.
type RestrictAllChatMembersConfig struct {
GroupControlConfig
}
// method returns CQ HTTP API method name for restricting all members.
func (config RestrictAllChatMembersConfig) method() string {
return "set_group_whole_ban"
}
// EnableAnonymousChatConfig contains fields to enable anonymous chat.
type EnableAnonymousChatConfig struct {
GroupControlConfig
}
// method returns CQ HTTP API method name for sending Message.
func (config EnableAnonymousChatConfig) method() string {
return "set_group_anonymous"
}
// LeaveChatConfig contains fields to leave a chat.
type LeaveChatConfig struct {
BaseChat
IsDismiss bool
}
// method returns CQ HTTP API method name for leaving chat.
func (config LeaveChatConfig) method() string {
switch config.ChatType {
case "discuss":
return "set_discuss_leave"
default:
return "set_group_leave"
}
}
// values returns url.Values representation of LeaveChatConfig.
func (config LeaveChatConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("is_dismiss", strconv.FormatBool(config.IsDismiss))
return v, nil
}
// HandleRequestConfig contains fields to handle a request.
type HandleRequestConfig struct {
RequestFlag string
Approve bool
}
// values returns url.Values representation of HandleRequestConfig.
func (config HandleRequestConfig) values() (url.Values, error) {
v := url.Values{}
v.Add("flag", config.RequestFlag)
v.Add("approve", strconv.FormatBool(config.Approve))
return v, nil
}
// HandleFriendRequestConfig contains fields to handle a friend request.
type HandleFriendRequestConfig struct {
HandleRequestConfig
Remark string
}
// method returns CQ HTTP API method name for handling friend requests.
func (config HandleFriendRequestConfig) method() string {
return "set_friend_add_request"
}
// values returns url.Values representation of HandleFriendRequestConfig.
func (config HandleFriendRequestConfig) values() (url.Values, error) {
v, err := config.HandleRequestConfig.values()
if err != nil {
return v, err
}
v.Add("remark", config.Remark)
return v, nil
}
// HandleGroupRequestConfig contains fields to handle a group adding request.
type HandleGroupRequestConfig struct {
HandleRequestConfig
Type string
Reason string
}
// method returns CQ HTTP API method name for handling group adding requests.
func (config HandleGroupRequestConfig) method() string {
return "set_group_add_request"
}
// values returns url.Values representation of HandleGroupRequestConfig.
func (config HandleGroupRequestConfig) values() (url.Values, error) {
v, err := config.HandleRequestConfig.values()
if err != nil {
return v, err
}
v.Add("type", config.Type)
v.Add("reason", config.Reason)
return v, nil
}
// UpdateConfig contains information about a GetUpdates request.
type UpdateConfig struct {
BaseUpdateConfig
Offset int
Limit int
Timeout int
}
// WebhookConfig contains information about a webhook.
type WebhookConfig struct {
BaseUpdateConfig
Pattern string // the webhook endpoint
}
// BaseUpdateConfig contains information about loading updates.
type BaseUpdateConfig struct {
PreloadUserInfo bool // if this is enabled, more information will be provided in Update.From
}