-
Notifications
You must be signed in to change notification settings - Fork 1
/
permission.go
165 lines (131 loc) · 4.7 KB
/
permission.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
package go_ts3
type PermissionGroupType int
//noinspection GoUnusedConst
const (
PermissionGroupTypeServerGroup PermissionGroupType = 0
PermissionGroupTypeGlobalClient PermissionGroupType = 1
PermissionGroupTypeChannel PermissionGroupType = 2
PermissionGroupTypeChannelGroup PermissionGroupType = 3
PermissionGroupTypeChannelClient PermissionGroupType = 4
)
// permfind `manage_scope, write_scope, read_scope`
type permissionFindRequest struct {
PermissionId int `schema:"permid,omitempty"`
StringPermissionId string `schema:"permsid,omitempty"`
}
type PermissionFindResponse struct {
Id int `json:"p,string"`
PermissionGroupType PermissionGroupType `json:"t,string"`
MajorId int `json:"id1,string"`
MinorId int `json:"id2,string"`
}
func (c *TeamspeakHttpClient) permissionFind(request permissionFindRequest) (*PermissionFindResponse, error) {
var perms []PermissionFindResponse
err := c.requestWithParams("permfind", request, &perms)
if err != nil {
return nil, err
}
return &perms[0], nil
}
func (c *TeamspeakHttpClient) PermissionFind(permissionId int) (*PermissionFindResponse, error) {
return c.permissionFind(permissionFindRequest{PermissionId: permissionId})
}
func (c *TeamspeakHttpClient) PermissionStringFind(permissionId string) (*PermissionFindResponse, error) {
return c.permissionFind(permissionFindRequest{StringPermissionId: permissionId})
}
// permget `manage_scope, write_scope, read_scope`
type permissionGetRequest struct {
PermissionId int `schema:"permid,omitempty"`
StringPermissionId string `schema:"permsid,omitempty"`
}
type PermissionGetResponse struct {
PermissionId int `schema:"permid"`
StringPermissionId string `schema:"permsid"`
PermissionValue int `json:"permvalue,string"`
}
func (c *TeamspeakHttpClient) permissionGet(request permissionGetRequest) (*PermissionGetResponse, error) {
var perms []PermissionGetResponse
err := c.requestWithParams("permget", request, &perms)
if err != nil {
return nil, err
}
return &perms[0], nil
}
func (c *TeamspeakHttpClient) PermissionGet(permissionId int) (*PermissionGetResponse, error) {
return c.permissionGet(permissionGetRequest{PermissionId: permissionId})
}
func (c *TeamspeakHttpClient) StringPermissionGet(permissionId string) (*PermissionGetResponse, error) {
return c.permissionGet(permissionGetRequest{StringPermissionId: permissionId})
}
// permidgetbyname `manage_scope, write_scope, read_scope`
type permissionGetByNameRequest struct {
Name string `schema:"permsid"`
}
type permissionGetByNameResponse struct {
Id int `json:"permid,string"`
}
func (c *TeamspeakHttpClient) PermissionGetByName(name string) (*int, error) {
var ids []permissionGetByNameResponse
err := c.requestWithParams("permidgetbyname", permissionGetByNameRequest{Name: name}, &ids)
if err != nil {
return nil, err
}
return &ids[0].Id, nil
}
// permissionlist `manage_scope, write_scope, read_scope`
type Permission struct {
PermissionId int `json:"permid,string"`
PermissionName string `json:"permname"`
PermissionDescription string `json:"permdesc"`
}
func (c *TeamspeakHttpClient) PermissionList() (*[]Permission, error) {
var permissions []Permission
err := c.request("permissionlist", &permissions)
if err != nil {
return nil, err
}
return &permissions, nil
}
// permoverview `manage_scope, write_scope, read_scope`
type permissionOverviewRequest struct {
ChannelId int `schema:"cid"`
ClientDbId int `schema:"cldbid"`
PermissionId int `schema:"permid"`
}
type PermissionOverview struct {
Id int `json:"p,string"`
PermissionGroupType PermissionGroupType `json:"t,string"`
MajorId int `json:"id1,string"`
MinorId int `json:"id2,string"`
Value int `json:"v,string"`
Negated int `json:"n,string"`
Skipped int `json:"s,string"`
}
func (c *TeamspeakHttpClient) PermissionOverview(channelId, clientDbId int) (*[]PermissionOverview, error) {
var permissions []PermissionOverview
err := c.requestWithParams(
"permoverview",
permissionOverviewRequest{
ChannelId: channelId,
ClientDbId: clientDbId,
PermissionId: 0,
},
&permissions,
)
if err != nil {
return nil, err
}
return &permissions, nil
}
// permreset `manage_scope`
type permissionResetResponse struct {
Token string `json:"token"`
}
func (c *TeamspeakHttpClient) PermissionReset() (*string, error) {
var tokens []permissionResetResponse
err := c.request("permreset", &tokens)
if err != nil {
return nil, err
}
return &tokens[0].Token, nil
}