-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
config_at.go
116 lines (107 loc) · 2.29 KB
/
config_at.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
package concern
import "github.com/Sora233/DDBOT/lsp/concern_type"
type AtSomeone struct {
Ctype concern_type.Type `json:"ctype"`
AtList []int64 `json:"at_list"`
}
// GroupConcernAtConfig @配置
type GroupConcernAtConfig struct {
AtAll concern_type.Type `json:"at_all"`
AtSomeone []*AtSomeone `json:"at_someone"`
}
func (g *GroupConcernAtConfig) CheckAtAll(ctype concern_type.Type) bool {
if g == nil {
return false
}
return g.AtAll.ContainAll(ctype)
}
func (g *GroupConcernAtConfig) GetAtSomeoneList(ctype concern_type.Type) []int64 {
if g == nil {
return nil
}
for _, at := range g.AtSomeone {
if at.Ctype.ContainAll(ctype) {
return at.AtList
}
}
return nil
}
func (g *GroupConcernAtConfig) SetAtSomeoneList(ctype concern_type.Type, ids []int64) {
if g == nil {
return
}
var found = false
for _, at := range g.AtSomeone {
if at.Ctype.ContainAll(ctype) {
found = true
at.AtList = ids
}
}
if !found {
g.AtSomeone = append(g.AtSomeone, &AtSomeone{
Ctype: ctype,
AtList: ids,
})
}
}
func (g *GroupConcernAtConfig) MergeAtSomeoneList(ctype concern_type.Type, ids []int64) {
if g == nil {
return
}
var found = false
for _, at := range g.AtSomeone {
if at.Ctype.ContainAll(ctype) {
found = true
var qqSet = make(map[int64]bool)
for _, id := range at.AtList {
qqSet[id] = true
}
for _, id := range ids {
qqSet[id] = true
}
at.AtList = nil
for id := range qqSet {
at.AtList = append(at.AtList, id)
}
}
}
if !found {
g.AtSomeone = append(g.AtSomeone, &AtSomeone{
Ctype: ctype,
AtList: ids,
})
}
}
func (g *GroupConcernAtConfig) RemoveAtSomeoneList(ctype concern_type.Type, ids []int64) {
if g == nil {
return
}
for _, at := range g.AtSomeone {
if at.Ctype.ContainAll(ctype) {
var qqSet = make(map[int64]bool)
for _, id := range at.AtList {
qqSet[id] = true
}
for _, id := range ids {
delete(qqSet, id)
}
at.AtList = nil
for id := range qqSet {
at.AtList = append(at.AtList, id)
}
}
}
}
func (g *GroupConcernAtConfig) ClearAtSomeoneList(ctype concern_type.Type) {
if g == nil {
return
}
var newList []*AtSomeone
for _, at := range g.AtSomeone {
if at.Ctype.ContainAll(ctype) {
continue
}
newList = append(newList, at)
}
g.AtSomeone = newList
}