-
Notifications
You must be signed in to change notification settings - Fork 1
/
servergroup.go
445 lines (384 loc) · 12.1 KB
/
servergroup.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
package go_ts3
type ServerGroupType int
//noinspection GoUnusedConst
const (
ServerGroupTypeChannelGuest ServerGroupType = 10
ServerGroupTypeServerGuest ServerGroupType = 15
ServerGroupTypeQueryGuest ServerGroupType = 20
ServerGroupTypeChannelVoice ServerGroupType = 25
ServerGroupTypeServerNormal ServerGroupType = 30
ServerGroupTypeChannelOperator ServerGroupType = 35
ServerGroupTypeChannelAdmin ServerGroupType = 40
ServerGroupTypeServerAdmin ServerGroupType = 45
ServerGroupTypeQueryAdmin ServerGroupType = 50
)
type GroupDatabaseType int
//noinspection GoUnusedConst
const (
GroupDatabaseTypeTemplate GroupDatabaseType = 0
GroupDatabaseTypeRegular GroupDatabaseType = 1
GroupDatabaseTypeQuery GroupDatabaseType = 2
)
// servergroupadd `manage_scope`
type serverGroupAddRequest struct {
Name string `schema:"name,required"`
GroupDatabaseType GroupDatabaseType `schema:"type,omitempty"`
}
type serverGroupAddResponse struct {
ServerGroupId int `json:"sgid,string"`
}
func (c *TeamspeakHttpClient) serverGroupAdd(request serverGroupAddRequest) (*int, error) {
var ids []serverGroupAddResponse
err := c.requestWithParams(
"servergroupadd",
request,
&ids,
)
if err != nil {
return nil, err
}
return &ids[0].ServerGroupId, nil
}
func (c *TeamspeakHttpClient) ServerGroupAdd(name string) (*int, error) {
return c.serverGroupAdd(serverGroupAddRequest{Name: name})
}
func (c *TeamspeakHttpClient) ServerGroupAddWithType(name string, groupType GroupDatabaseType) (*int, error) {
return c.serverGroupAdd(serverGroupAddRequest{Name: name, GroupDatabaseType: groupType})
}
// servergroupaddclient `manage_scope`
type serverGroupAddClientRequest struct {
ServerGroupId int `schema:"sgid,required"`
ClientDbId int `schema:"cldbid,required"`
}
func (c *TeamspeakHttpClient) ServerGroupAddClient(serverGroupId, clientDbId int) error {
return c.requestWithParams(
"servergroupaddclient",
serverGroupAddClientRequest{
ServerGroupId: serverGroupId,
ClientDbId: clientDbId,
},
nil,
)
}
// servergroupaddperm `manage_scope`
type serverGroupAddPermissionRequest struct {
ServerGroupId int `schema:"sgid"`
PermissionId int `schema:"permid"`
PermissionValue int `schema:"permvalue"`
PermNegated int `schema:"permnegated"`
PermSkip int `schema:"permskip"`
}
func (c *TeamspeakHttpClient) ServerGroupAddPermission(
serverGroupId, permissionId, permissionValue int,
permSkip, permNegated bool,
) error {
return c.requestWithParams(
"servergroupaddperm",
serverGroupAddPermissionRequest{
ServerGroupId: serverGroupId,
PermissionId: permissionId,
PermissionValue: permissionValue,
PermNegated: boolToInt(permNegated),
PermSkip: boolToInt(permSkip),
},
nil,
)
}
type serverGroupAddStringPermissionRequest struct {
ServerGroupId int `schema:"sgid"`
PermissionStringId string `schema:"permsid"`
PermissionValue int `schema:"permvalue"`
PermNegated int `schema:"permnegated"`
PermSkip int `schema:"permskip"`
}
func (c *TeamspeakHttpClient) ServerGroupAddStringPermission(
serverGroupId int,
permissionStringId string,
permissionValue int,
permSkip, permNegated bool,
) error {
return c.requestWithParams(
"servergroupaddperm",
serverGroupAddStringPermissionRequest{
ServerGroupId: serverGroupId,
PermissionStringId: permissionStringId,
PermissionValue: permissionValue,
PermNegated: boolToInt(permNegated),
PermSkip: boolToInt(permSkip),
},
nil,
)
}
// servergroupautoaddperm `manage_scope`
type serverGroupAutoAddPermissionRequest struct {
ServerGroupType ServerGroupType `schema:"sgtype"`
PermissionId int `schema:"permid"`
PermissionValue int `schema:"permvalue"`
PermNegated int `schema:"permnegated"`
PermSkip int `schema:"permskip"`
}
func (c *TeamspeakHttpClient) ServerGroupAutoAddPermission(
serverGroupType ServerGroupType,
permissionId, permissionValue int,
permSkip, permNegated bool,
) error {
return c.requestWithParams(
"servergroupaddperm",
serverGroupAutoAddPermissionRequest{
ServerGroupType: serverGroupType,
PermissionId: permissionId,
PermissionValue: permissionValue,
PermNegated: boolToInt(permNegated),
PermSkip: boolToInt(permSkip),
},
nil,
)
}
type serverGroupAutoAddStringPermissionRequest struct {
ServerGroupType ServerGroupType `schema:"sgtype"`
PermissionStringId string `schema:"permsid"`
PermissionValue int `schema:"permvalue"`
PermNegated int `schema:"permnegated"`
PermSkip int `schema:"permskip"`
}
func (c *TeamspeakHttpClient) ServerGroupAutoAddStringPermission(
serverGroupType ServerGroupType,
permissionStringId string,
permissionValue int,
permSkip, permNegated bool,
) error {
return c.requestWithParams(
"servergroupautoaddperm",
serverGroupAutoAddStringPermissionRequest{
ServerGroupType: serverGroupType,
PermissionStringId: permissionStringId,
PermissionValue: permissionValue,
PermNegated: boolToInt(permNegated),
PermSkip: boolToInt(permSkip),
},
nil,
)
}
// servergroupautodelperm `manage_scope`
type serverGroupAutoDeletePermissionRequest struct {
ServerGroupType ServerGroupType `schema:"sgtype"`
PermissionId int `schema:"permid"`
}
func (c *TeamspeakHttpClient) ServerGroupAutoDeletePermission(serverGroupType ServerGroupType, permissionId int) error {
return c.requestWithParams(
"servergroupautodelperm",
serverGroupAutoDeletePermissionRequest{
ServerGroupType: serverGroupType,
PermissionId: permissionId,
},
nil,
)
}
type serverGroupAutoDeleteStringPermissionRequest struct {
ServerGroupType ServerGroupType `schema:"sgtype"`
StringPermissionId string `schema:"permsid"`
}
func (c *TeamspeakHttpClient) ServerGroupAutoDeleteStringPermission(serverGroupType ServerGroupType, stringPermissionId string) error {
return c.requestWithParams(
"servergroupautodelperm",
serverGroupAutoDeleteStringPermissionRequest{
ServerGroupType: serverGroupType,
StringPermissionId: stringPermissionId,
},
nil,
)
}
// servergroupclientlist `manage_scope`
type serverGroupClientListRequest struct {
ServerGroupId int `schema:"sgid"`
Names bool `schema:"names,omitempty"`
}
type ServerGroupClientList struct {
ClientDbId int `json:"cldbid,string"`
ClientNickname string `json:"client_nickname"`
ClientUniqueIdentifier string `json:"client_unique_identifier"`
}
func (c *TeamspeakHttpClient) ServerGroupClientList(serverGroupId int) (*[]ServerGroupClientList, error) {
var clients []ServerGroupClientList
err := c.requestWithParams(
"servergroupclientlist",
serverGroupClientListRequest{
ServerGroupId: serverGroupId,
Names: true,
},
&clients,
)
if err != nil {
return nil, err
}
return &clients, nil
}
// servergroupcopy `manage_scope`
type serverGroupCopyRequest struct {
SourceGroupId int `schema:"ssgid"`
TargetGroupId int `schema:"tsgid"`
Name string `schema:"name"`
Type GroupDatabaseType `schema:"type"`
}
type serverGroupCopyResponse struct {
ServerGroupId int `json:"sgid,string"`
}
func (c *TeamspeakHttpClient) ServerGroupCopy(sourceGroupId, targetGroupId int, name string, groupType GroupDatabaseType) (*int, error) {
var ids []serverGroupCopyResponse
err := c.requestWithParams(
"servergroupcopy",
serverGroupCopyRequest{
SourceGroupId: sourceGroupId,
TargetGroupId: targetGroupId,
Name: name,
Type: groupType,
},
&ids,
)
if err != nil {
return nil, err
}
return &ids[0].ServerGroupId, nil
}
// servergroupdel `manage_scope`
type serverGroupDeleteRequest struct {
ServerGroupId int `schema:"sgid"`
Force int `schema:"force"`
}
func (c *TeamspeakHttpClient) ServerGroupDelete(serverGroupId int, force bool) error {
return c.requestWithParams(
"servergroupdel",
serverGroupDeleteRequest{
ServerGroupId: serverGroupId,
Force: boolToInt(force),
},
nil,
)
}
// servergroupdelclient `manage_scope`
type serverGroupDeleteClientRequest struct {
ServerGroupId int `schema:"sgid,required"`
ClientDbId int `schema:"cldbid,required"`
}
func (c *TeamspeakHttpClient) ServerGroupDeleteClient(serverGroupId, clientDbId int) error {
return c.requestWithParams(
"servergroupdelclient",
serverGroupDeleteClientRequest{
ServerGroupId: serverGroupId,
ClientDbId: clientDbId,
},
nil,
)
}
// servergroupdelperm `manage_scope`
type ServerGroupDeletePermissionRequest struct {
ServerGroupId int `schema:"sgid,required"`
PermissionId []int `schema:"permid,omitempty"`
StringPermissionId []string `schema:"permsid,omitempty"`
}
func (c *TeamspeakHttpClient) ServerGroupDeletePermission(request ServerGroupDeletePermissionRequest) error {
return c.requestWithParams("servergroupdelperm", request, nil)
}
// servergrouplist `manage_scope`
type ServerGroup struct {
ServerGroupId int `json:"sgid,string"`
Type GroupDatabaseType `json:"type,string"`
Name string `json:"name"`
NameMode int `json:"namemode,string"`
IconId int `json:"iconid,string"`
NMemberAddp int `json:"n_member_addp,string"`
NMemberRemovep int `json:"n_member_removep,string"`
NModifyp int `json:"n_modifyp,string"`
SaveDb int `json:"savedb,string"`
SortId int `json:"sortid,string"`
}
func (c *TeamspeakHttpClient) ServerGroupList() (*[]ServerGroup, error) {
var serverGroups []ServerGroup
err := c.request("servergrouplist", &serverGroups)
if err != nil {
return nil, err
}
return &serverGroups, nil
}
// servergrouppermlist `manage_scope`
type serverGroupPermsListRequest struct {
ServerGroupId int `schema:"sgid"`
AsString bool `schema:"-permsid,omitempty"`
}
type ServerGroupPermission struct {
PermissionId int `json:"permid,string"`
PermissionValue int `json:"permvalue,string"`
PermissionNegated int `json:"permnegated,string"`
PermSkip int `json:"permskip,string"`
}
func (c *TeamspeakHttpClient) ServerGroupPermissionList(serverGroupId int) (*[]ServerGroupPermission, error) {
var perms []ServerGroupPermission
err := c.requestWithParams(
"servergrouppermlist",
serverGroupPermsListRequest{
ServerGroupId: serverGroupId,
AsString: false,
},
nil,
)
if err != nil {
return nil, err
}
return &perms, nil
}
type ServerGroupStringPermission struct {
StringPermissionId string `json:"permid"`
PermissionValue int `json:"permvalue,string"`
PermissionNegated int `json:"permnegated,string"`
PermSkip int `json:"permskip,string"`
}
func (c *TeamspeakHttpClient) ServerGroupStringPermissionList(serverGroupId int) (*[]ServerGroupStringPermission, error) {
var perms []ServerGroupStringPermission
err := c.requestWithParams(
"servergrouppermlist",
serverGroupPermsListRequest{
ServerGroupId: serverGroupId,
AsString: true,
},
nil,
)
if err != nil {
return nil, err
}
return &perms, nil
}
// servergrouprename `manage_scope`
type serverGroupRenameRequest struct {
ServerGroupId int `schema:"sgid"`
Name string `schema:"name"`
}
func (c *TeamspeakHttpClient) ServerGroupRename(serverGroupId int, name string) error {
return c.requestWithParams(
"servergrouprename",
serverGroupRenameRequest{
ServerGroupId: serverGroupId,
Name: name,
},
nil,
)
}
// servergroupsbyclientid `manage_scope`
type serverGroupsByClientIdRequest struct {
ClientDbId int `schema:"cldbid"`
}
type ServerGroupsByClientIdResponse struct {
GroupName string `json:"name"`
GroupId int `json:"sgid,string"`
}
func (c *TeamspeakHttpClient) ServerGroupsByClientId(clientDbId int) (*[]ServerGroupsByClientIdResponse, error) {
var groups []ServerGroupsByClientIdResponse
err := c.requestWithParams(
"servergroupsbyclientid",
serverGroupsByClientIdRequest{ClientDbId: clientDbId},
&groups,
)
if err != nil {
return nil, err
}
return &groups, nil
}