1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-16 11:54:29 +00:00
arikawa/bot/nameflag.go

41 lines
565 B
Go
Raw Normal View History

2020-01-19 06:06:00 +00:00
package bot
import "strings"
type NameFlag uint64
const FlagSeparator = 'ー'
const (
None NameFlag = 1 << iota
// These flags only apply to messageCreate events.
Raw // R
AdminOnly // A
)
func ParseFlag(name string) (NameFlag, string) {
parts := strings.SplitN(name, string(FlagSeparator), 2)
if len(parts) != 2 {
return 0, name
}
var f NameFlag
for _, r := range parts[0] {
switch r {
case 'R':
f |= Raw
case 'A':
f |= AdminOnly
}
}
return f, parts[1]
}
func (f NameFlag) Is(flag NameFlag) bool {
return f&flag != 0
}