-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser.go
47 lines (40 loc) · 923 Bytes
/
user.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
package main
import (
"strconv"
"time"
"fmt"
)
/* Registered users can moderate, own channels, etc. */
type User struct {
Name string
Password string
Created time.Time
//Identifiers string // JSON
Attributes map[string]string
Session string
}
// generate channel property name
// conveniece
func chanPropName(chanName string, propName string) string {
return fmt.Sprintf("%s.%s", chanName, propName)
}
// get mod priviledge level
func (user *User) GetModLevel(chanName string) int {
key := chanPropName(chanName, "modlevel")
attr, ok := user.Attributes[key]
if ok {
modlevel, err := strconv.Atoi(attr)
if err == nil {
return modlevel
}
}
return 0
}
// is a channel janitor
func (user *User) IsChanJan(chanName string) bool {
return user.GetModLevel(chanName) > 0
}
// is a channel Moderator
func (user *User) IsChanMod(chanName string) bool {
return user.GetModLevel(chanName) > 1
}