-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.go
More file actions
46 lines (42 loc) · 1.35 KB
/
Copy pathrole.go
File metadata and controls
46 lines (42 loc) · 1.35 KB
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
package nerimity
// ServerRole is a role within a server. Roles carry a permission bitfield;
// test it with HasBit and the Perm* constants.
type ServerRole struct {
client *Client
// ID is the role's unique ID.
ID string
// Name is the role's display name.
Name string
// Permissions is the role's permission bitfield.
Permissions int
// HexColor is the role's colour, e.g. "#ffaa00".
HexColor string
// Order is the role's position in the hierarchy.
Order int
// ServerID is the ID of the server this role belongs to.
ServerID string
// IsDefaultRole reports whether this is the server's @everyone role.
IsDefaultRole bool
}
func newServerRole(client *Client, raw rawServerRole) *ServerRole {
r := &ServerRole{
client: client,
ID: raw.ID,
Name: raw.Name,
Permissions: raw.Permissions,
HexColor: raw.HexColor,
Order: raw.Order,
ServerID: raw.ServerID,
}
if s, ok := client.servers.get(raw.ServerID); ok {
r.IsDefaultRole = s.DefaultRoleID == r.ID
}
return r
}
// HasPermission reports whether the role's own bitfield includes perm. Note
// this checks the role in isolation; to check what a member can actually do
// (accounting for @everyone, admin and server ownership) use
// ServerMember.HasPermission.
func (r *ServerRole) HasPermission(perm RolePermission) bool {
return HasBit(r.Permissions, int(perm))
}