-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPermission.go
54 lines (41 loc) · 1.36 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
package unison
import (
"strconv"
"github.com/sirupsen/logrus"
)
// DiscordPermissionFlags limits member accessability to discord guilds/channels functionality
// https://discordapp.com/developers/docs/topics/permissions
type DiscordPermissionFlags uint64
func init() {
// make sure the ToStr and other methods
if uint64(DiscordPermissionFlags(0x8000040000200001)) != uint64(0x8000040000200001) {
logrus.Fatal("Did the DiscordPermissionFalgs type change? update ToStr() method.")
}
}
type DiscordPermissions struct {
flags DiscordPermissionFlags
}
func NewDiscordPermissionsDiscordgoWrapper(flags int, err error) (*DiscordPermissions, error) {
return &DiscordPermissions{flags: DiscordPermissionFlags(flags)}, err
}
func (dp *DiscordPermissions) Add(flags DiscordPermissionFlags) {
dp.flags |= flags
}
func (dp *DiscordPermissions) Remove(flags DiscordPermissionFlags) {
// be sure the flags exist
dp.Add(flags)
// Remove the desired flags
dp.flags ^= flags
}
func (dp *DiscordPermissions) Set(flags DiscordPermissionFlags) {
dp.flags = flags
}
func (dp *DiscordPermissions) Get() DiscordPermissionFlags {
return dp.flags
}
func (dp *DiscordPermissions) HasRequiredPermissions(permission *DiscordPermissions) bool {
return (permission.Get() & dp.flags) == dp.flags
}
func (dp *DiscordPermissions) ToStr() string {
return strconv.FormatUint(uint64(dp.flags), 10)
}