-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
603 lines (510 loc) · 20.6 KB
/
client.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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
package go_ts3
import "errors"
// clientaddperm `manage_scope`
type clientAddPermissionRequest struct {
ClientDbId int `schema:"cldbid"`
PermissionId int `schema:"permid"`
PermissionValue int `schema:"permvalue"`
PermSkip int `schema:"permskip"`
}
func (c *TeamspeakHttpClient) ClientAddPermission(clientDbId, permissionId, permissionValue int, permSkip bool) error {
return c.requestWithParams(
"clientaddperm",
clientAddPermissionRequest{
ClientDbId: clientDbId,
PermissionId: permissionId,
PermissionValue: permissionValue,
PermSkip: boolToInt(permSkip),
},
nil,
)
}
type clientAddStringPermissionRequest struct {
ClientDbId int `schema:"cldbid"`
PermissionName string `schema:"permsid"`
PermissionValue int `schema:"permvalue"`
PermSkip int `schema:"permskip"`
}
func (c *TeamspeakHttpClient) ClientAddStringPermission(clientDbId int, permissionName string, permissionValue int, permSkip bool) error {
return c.requestWithParams(
"clientaddperm",
clientAddStringPermissionRequest{
ClientDbId: clientDbId,
PermissionName: permissionName,
PermissionValue: permissionValue,
PermSkip: boolToInt(permSkip),
},
nil,
)
}
// clientdbdelete `manage_scope, write_scope`
type clientDbDeleteRequest struct {
ClientDbId int `schema:"cldbid,required"`
}
func (c *TeamspeakHttpClient) ClientDbDelete(clientDbId int) error {
return c.requestWithParams("clientdbdelete", clientDbDeleteRequest{ClientDbId: clientDbId}, nil)
}
// clientdbedit `manage_scope, write_scope`
type ClientDbEditRequest struct {
ClientDbId int `schema:"cldbid,required"`
ClientNickname string `schema:"client_nickname"`
ClientIsTalker string `schema:"client_is_talker"`
ClientDescription string `schema:"client_description"`
ClientIsChannelCommander string `schema:"client_is_channel_commander"`
ClientIconID string `schema:"client_icon_id"`
}
func (c *TeamspeakHttpClient) ClientDbEdit(request ClientDbEditRequest) error {
return c.requestWithParams("clientdbedit", request, nil)
}
// clientdbfind `manage_scope, write_scope, read_scope`
type clientDbFindRequest struct {
IsUid bool `schema:"-uid,omitempty"`
Pattern string `schema:"pattern"`
}
type ClientDbFindResponse struct {
ClientDbId []int `json:"cldbid,string"`
}
func (c *TeamspeakHttpClient) clientDbFind(request clientDbFindRequest) (*[]ClientDbFindResponse, error) {
var clients []ClientDbFindResponse
err := c.requestWithParams("clientdbfind", request, &clients)
if err != nil {
return nil, err
}
return &clients, err
}
func (c *TeamspeakHttpClient) ClientDbFindName(pattern string) (*[]ClientDbFindResponse, error) {
return c.clientDbFind(clientDbFindRequest{
IsUid: false,
Pattern: pattern,
})
}
func (c *TeamspeakHttpClient) ClientDbFindUid(uid int) (*[]ClientDbFindResponse, error) {
return c.clientDbFind(clientDbFindRequest{
IsUid: true,
Pattern: string(uid),
})
}
// clientdbinfo `manage_scope, write_scope, read_scope`
type clientDbInfoRequest struct {
ClientDbId int `schema:"cldbid,required"`
}
type ClientDbInfo struct {
ClientBase64HashClientUID string `json:"client_base64HashClientUID"`
ClientCreated int `json:"client_created,string"`
ClientDatabaseID int `json:"client_database_id,string"`
ClientDescription string `json:"client_description"`
ClientFlagAvatar string `json:"client_flag_avatar"`
ClientLastconnected int `json:"client_lastconnected,string"`
ClientLastip string `json:"client_lastip"`
ClientMonthBytesDownloaded int `json:"client_month_bytes_downloaded,string"`
ClientMonthBytesUploaded int `json:"client_month_bytes_uploaded,string"`
ClientNickname string `json:"client_nickname"`
ClientTotalBytesDownloaded int `json:"client_total_bytes_downloaded,string"`
ClientTotalBytesUploaded int `json:"client_total_bytes_uploaded,string"`
ClientTotalconnections int `json:"client_totalconnections,string"`
ClientUniqueIdentifier string `json:"client_unique_identifier"`
}
func (c *TeamspeakHttpClient) ClientDbInfo(clientDbId int) (*ClientDbInfo, error) {
var clientDbInfos []ClientDbInfo
err := c.requestWithParams(
"clientdbinfo",
clientDbInfoRequest{ClientDbId: clientDbId},
&clientDbInfos,
)
if err != nil {
return nil, err
}
return &clientDbInfos[0], nil
}
// clientdblist `manage_scope, write_scope, read_scope`
type ClientDbListRequest struct {
Start int `schema:"start,omitempty"`
Duration int `schema:"duration,omitempty"`
}
type DbClient struct {
Cldbid int `json:"cldbid,string"`
ClientCreated int `json:"client_created,string"`
ClientDescription string `json:"client_description"`
ClientLastConnected int `json:"client_lastconnected,string"`
ClientLastIP string `json:"client_lastip"`
ClientLoginName string `json:"client_login_name"`
ClientNickname string `json:"client_nickname"`
ClientTotalConnections int `json:"client_totalconnections,string"`
ClientUniqueIdentifier string `json:"client_unique_identifier"`
}
func (c *TeamspeakHttpClient) ClientDbList(request ClientDbListRequest) (*[]DbClient, error) {
var clients []DbClient
err := c.requestWithParams("clientdblist", request, &clients)
if err != nil {
return nil, err
}
return &clients, nil
}
// clientdelperm `manage_scope`
type ClientDeletePermission struct {
ClientDbId int `schema:"cldbid,required"`
PermId []int `schema:"permid"`
PermsId []string `schema:"permsid"`
}
func (c *TeamspeakHttpClient) ClientDeletePermission(request ClientDeletePermission) error {
return c.requestWithParams("clientdelperm", request, nil)
}
// clientedit `manage_scope, write_scope`
type ClientEditRequest struct {
ClientId int `schema:"clid,required"`
ClientNickname string `schema:"client_nickname"`
ClientIsTalker string `schema:"client_is_talker"`
ClientDescription string `schema:"client_description"`
ClientIsChannelCommander string `schema:"client_is_channel_commander"`
ClientIconID string `schema:"client_icon_id"`
}
func (c *TeamspeakHttpClient) ClientEdit(request ClientEditRequest) error {
return c.requestWithParams("clientedit", request, nil)
}
// clientfind `manage_scope, write_scope, read_scope`
type clientFindRequest struct {
Pattern string `schema:"pattern,required"`
}
type ClientFindResponse struct {
ClientId int `json:"clid,string"`
ClientNickname string `json:"client_nickname"`
}
func (c *TeamspeakHttpClient) ClientFind(pattern string) (*[]ClientFindResponse, error) {
var clients []ClientFindResponse
err := c.requestWithParams("clientfind", clientFindRequest{Pattern: pattern}, clients)
if err != nil {
return nil, err
}
return &clients, nil
}
// clientgetdbidfromuid `manage_scope, write_scope, read_scope`
type clientGetDbIdFromUidRequest struct {
ClientUid string `schema:"cluid,required"`
}
type clientGetDbIdFromUidResponse struct {
ClientDbId int `json:"cldbid,string"`
}
func (c *TeamspeakHttpClient) ClientGetDbIdFromUid(clientUid string) (*int, error) {
var clients []clientGetDbIdFromUidResponse
err := c.requestWithParams(
"clientgetdbidfromuid",
clientGetDbIdFromUidRequest{ClientUid: clientUid},
&clients,
)
if err != nil {
return nil, err
}
return &clients[0].ClientDbId, nil
}
// clientgetids `manage_scope, write_scope, read_scope`
type clientGetIdsRequest struct {
ClientUid string `schema:"cluid,required"`
}
type ClientGetIdsResponse struct {
ClientUid string `json:"cluid"`
ClientId int `json:"clid,string"`
Name string `json:"name"`
}
func (c *TeamspeakHttpClient) ClientGetIds(clientUid string) (*ClientGetIdsResponse, error) {
var clients []ClientGetIdsResponse
err := c.requestWithParams(
"clientgetids",
clientGetIdsRequest{ClientUid: clientUid},
&clients,
)
if err != nil {
return nil, err
}
return &clients[0], nil
}
// clientgetnamefromdbid `manage_scope, write_scope, read_scope`
type clientGetNameFromDbIdRequest struct {
ClientDbId int `schema:"cldbid,required"`
}
type clientGetNameFromDbIdResponse struct {
ClientUid string `json:"cluid"`
ClientDbId int `json:"cldbid,string"`
Name string `json:"name"`
}
func (c *TeamspeakHttpClient) ClientGetNameFromDbId(clientDbId int) (*clientGetNameFromDbIdResponse, error) {
var clients []clientGetNameFromDbIdResponse
err := c.requestWithParams(
"clientgetnamefromdbid",
clientGetNameFromDbIdRequest{ClientDbId: clientDbId},
&clients,
)
if err != nil {
return nil, err
}
return &clients[0], nil
}
// clientgetnamefromuid `manage_scope, write_scope, read_scope`
type clientGetNameFromUidRequest struct {
ClientUid string `schema:"cldbid,required"`
}
type clientGetNameFromUidResponse struct {
ClientUid string `json:"cluid"`
ClientDbId int `json:"cldbid,string"`
Name string `json:"name"`
}
func (c *TeamspeakHttpClient) ClientGetNameFromUid(clientUid string) (*clientGetNameFromUidResponse, error) {
var clients []clientGetNameFromUidResponse
err := c.requestWithParams(
"clientgetnamefromdbid",
clientGetNameFromUidRequest{ClientUid: clientUid},
&clients,
)
if err != nil {
return nil, err
}
return &clients[0], nil
}
// clientgetuidfromclid `manage_scope, write_scope, read_scope`
type clientGetUidFromClientIdRequest struct {
ClientId int `schema:"clid,required"`
}
type clientGetUidFromClientIdResponse struct {
ClientId int `json:"clid,string"`
ClientUid string `json:"cluid"`
NickName string `json:"nickname"`
}
func (c *TeamspeakHttpClient) ClientGetUidFromClientId(clientId int) (*clientGetUidFromClientIdResponse, error) {
var clients []clientGetUidFromClientIdResponse
err := c.requestWithParams(
"clientgetuidfromclid",
clientGetUidFromClientIdRequest{ClientId: clientId},
&clients,
)
if err != nil {
return nil, err
}
return &clients[0], nil
}
// clientinfo `manage_scope, write_scope, read_scope`
type clientInfoRequest struct {
ClientId int `schema:"clid"`
}
type ClientInfo struct {
ClientId int `json:"cid,string"`
ClientAway int `json:"client_away,string"`
ClientAwayMessage string `json:"client_away_message"`
ClientBadges string `json:"client_badges"`
ClientBase64HashClientUID string `json:"client_base64HashClientUID"`
ClientChannelGroupID int `json:"client_channel_group_id,string"`
ClientChannelGroupInheritedChannelID int `json:"client_channel_group_inherited_channel_id,string"`
ClientCountry string `json:"client_country"`
ClientCreated int `json:"client_created,string"`
ClientDatabaseID int `json:"client_database_id,string"`
ClientDefaultChannel string `json:"client_default_channel"`
ClientDefaultToken string `json:"client_default_token"`
ClientDescription string `json:"client_description"`
ClientFlagAvatar string `json:"client_flag_avatar"`
ClientIconID int `json:"client_icon_id,string"`
ClientIdleTime int `json:"client_idle_time,string"`
ClientInputHardware int `json:"client_input_hardware,string"`
ClientInputMuted int `json:"client_input_muted,string"`
ClientIntegrations string `json:"client_integrations"`
ClientIsChannelCommander int `json:"client_is_channel_commander,string"`
ClientIsPrioritySpeaker int `json:"client_is_priority_speaker,string"`
ClientIsRecording int `json:"client_is_recording,string"`
ClientIsTalker int `json:"client_is_talker,string"`
ClientLastconnected int `json:"client_lastconnected,string"`
ClientLoginName string `json:"client_login_name"`
ClientMetaData string `json:"client_meta_data"`
ClientMonthBytesDownloaded int `json:"client_month_bytes_downloaded,string"`
ClientMonthBytesUploaded int `json:"client_month_bytes_uploaded,string"`
ClientMyteamspeakAvatar string `json:"client_myteamspeak_avatar"`
ClientMyteamspeakID string `json:"client_myteamspeak_id"`
ClientNeededServerqueryViewPower int `json:"client_needed_serverquery_view_power,string"`
ClientNickname string `json:"client_nickname"`
ClientNicknamePhonetic string `json:"client_nickname_phonetic"`
ClientOutputHardware int `json:"client_output_hardware,string"`
ClientOutputMuted int `json:"client_output_muted,string"`
ClientOutputonlyMuted int `json:"client_outputonly_muted,string"`
ClientPlatform string `json:"client_platform"`
ClientSecurityHash string `json:"client_security_hash"`
ClientServergroups int `json:"client_servergroups,string"`
ClientSignedBadges string `json:"client_signed_badges"`
ClientTalkPower int `json:"client_talk_power,string"`
ClientTalkRequest int `json:"client_talk_request,string"`
ClientTalkRequestMsg string `json:"client_talk_request_msg"`
ClientTotalBytesDownloaded int `json:"client_total_bytes_downloaded,string"`
ClientTotalBytesUploaded int `json:"client_total_bytes_uploaded,string"`
ClientTotalconnections int `json:"client_totalconnections,string"`
ClientType int `json:"client_type,string"`
ClientUniqueIdentifier string `json:"client_unique_identifier"`
ClientUnreadMessages int `json:"client_unread_messages,string"`
ClientVersion string `json:"client_version"`
ClientVersionSign string `json:"client_version_sign"`
ConnectionBandwidthReceivedLastMinuteTotal int `json:"connection_bandwidth_received_last_minute_total,string"`
ConnectionBandwidthReceivedLastSecondTotal int `json:"connection_bandwidth_received_last_second_total,string"`
ConnectionBandwidthSentLastMinuteTotal int `json:"connection_bandwidth_sent_last_minute_total,string"`
ConnectionBandwidthSentLastSecondTotal int `json:"connection_bandwidth_sent_last_second_total,string"`
ConnectionBytesReceivedTotal int `json:"connection_bytes_received_total,string"`
ConnectionBytesSentTotal int `json:"connection_bytes_sent_total,string"`
ConnectionClientIP string `json:"connection_client_ip"`
ConnectionConnectedTime int `json:"connection_connected_time,string"`
ConnectionFiletransferBandwidthReceived int `json:"connection_filetransfer_bandwidth_received,string"`
ConnectionFiletransferBandwidthSent int `json:"connection_filetransfer_bandwidth_sent,string"`
ConnectionPacketsReceivedTotal int `json:"connection_packets_received_total,string"`
ConnectionPacketsSentTotal int `json:"connection_packets_sent_total,string"`
}
func (c *TeamspeakHttpClient) ClientInfo(clientId int) (*[]ClientInfo, error) {
var clients []ClientInfo
err := c.requestWithParams(
"clientinfo",
clientInfoRequest{ClientId: clientId},
&clients,
)
if err != nil {
return nil, err
}
return &clients, nil
}
// clientkick `manage_scope, write_scope`
type clientKickRequest struct {
ClientId []int `schema:"clid,required"`
ReasonId int `schema:"reasonid,required"`
ReasonMessage string `schema:"reasonmsg,omitempty"`
}
func (c *TeamspeakHttpClient) clientKick(request clientKickRequest) error {
if len(request.ReasonMessage) > 40 {
return errors.New("the message must not have more than 40 characters")
}
return c.requestWithParams("clientkick", request, nil)
}
func (c *TeamspeakHttpClient) ClientKickChannel(clientIds []int, reasonMessage string) error {
return c.clientKick(clientKickRequest{
ClientId: clientIds,
ReasonId: 4,
ReasonMessage: reasonMessage,
})
}
func (c *TeamspeakHttpClient) ClientKickServer(clientIds []int, reasonMessage string) error {
return c.clientKick(clientKickRequest{
ClientId: clientIds,
ReasonId: 5,
ReasonMessage: reasonMessage,
})
}
// clientlist `manage_scope, write_scope, read_scope`
type Client struct {
ChannelId int `json:"cid,string"`
ClientId int `json:"clid,string"`
ClientDatabaseId int `json:"client_database_id,string"`
ClientNickname string `json:"client_nickname"`
ClientType int `json:"client_type,string"`
}
func (u *Client) IsBot() bool {
return u.ClientType == 1
}
func (c *TeamspeakHttpClient) ClientList() (*[]Client, error) {
var users []Client
err := c.request("clientlist", &users)
if err != nil {
return nil, err
}
return &users, nil
}
// clientmove `manage_scope, write_scope`
type ClientMoveRequest struct {
ClientId []int `schema:"clid,required"`
ChannelId int `schema:"cid,required"`
ChannelPassword string `schema:"cpw,omitempty"`
}
func (c *TeamspeakHttpClient) ClientMove(request ClientMoveRequest) error {
return c.requestWithParams("clientmove", request, nil)
}
// clientpermlist `manage_scope, write_scope, read_scope`
type clientPermissionListRequest struct {
ClientDbId int `schema:"cldbid"`
AsString bool `schema:"-permsid,omitempty"`
}
type ClientPermissionListResponse struct {
PermissionId int `json:"permid,string"`
PermissionNegated int `json:"permnegated,string"`
PermissionSkip int `json:"permskip,string"`
PermissionValue int `json:"permvalue,string"`
}
func (c *TeamspeakHttpClient) ClientPermissionList(clientDbId int) (*[]ClientPermissionListResponse, error) {
var perms []ClientPermissionListResponse
err := c.requestWithParams(
"clientpermlist",
clientPermissionListRequest{
ClientDbId: clientDbId,
},
&perms,
)
if err != nil {
return nil, err
}
return &perms, nil
}
type ClientStringPermissionListResponse struct {
PermissionId string `json:"permsid"`
PermissionNegated int `json:"permnegated,string"`
PermissionSkip int `json:"permskip,string"`
PermissionValue int `json:"permvalue,string"`
}
func (c *TeamspeakHttpClient) ClientStringPermissionList(clientDbId int) (*[]ClientStringPermissionListResponse, error) {
var perms []ClientStringPermissionListResponse
err := c.requestWithParams(
"clientpermlist",
clientPermissionListRequest{
ClientDbId: clientDbId,
AsString: true,
},
&perms,
)
if err != nil {
return nil, err
}
return &perms, nil
}
// clientpoke `manage_scope, write_scope`
type clientPokeRequest struct {
ClientId int `schema:"clid,required"`
Message string `schema:"msg,required"`
}
func (c *TeamspeakHttpClient) ClientPoke(clientId int, message string) error {
return c.requestWithParams("clientpoke", clientPokeRequest{ClientId: clientId, Message: message}, nil)
}
// clientsetserverquerylogin `manage_scope, write_scope`
type clientSetServerQueryLoginRequest struct {
ClientLoginName string `schema:"client_login_name"`
}
func (c *TeamspeakHttpClient) ClientSetServerQueryLogin(clientLoginName string) error {
return c.requestWithParams(
"clientsetserverquerylogin",
clientSetServerQueryLoginRequest{ClientLoginName: clientLoginName},
nil,
)
}
// clientupdate `manage_scope, write_scope`
type ClientUpdateRequest struct {
ClientNickname string `schema:"client_nickname"`
ClientIsTalker string `schema:"client_is_talker"`
ClientDescription string `schema:"client_description"`
ClientIsChannelCommander string `schema:"client_is_channel_commander"`
ClientIconID string `schema:"client_icon_id"`
}
func (c *TeamspeakHttpClient) ClientUpdate(request ClientUpdateRequest) error {
return c.requestWithParams("clientupdate", request, nil)
}
// setclientchannelgroup `manage_scope, write_scope`
type setClientChannelGroupRequest struct {
ChannelGroupId int `schema:"cgid"`
ChannelId int `schema:"cid"`
ClientDbId int `schema:"cldbid"`
}
func (c *TeamspeakHttpClient) SetClientChannelGroup(channelGroupId, channelId, clientDbId int) error {
return c.requestWithParams(
"setclientchannelgroup",
setClientChannelGroupRequest{
ChannelGroupId: channelGroupId,
ChannelId: channelId,
ClientDbId: clientDbId,
},
nil,
)
}