1
|
|
|
package bot |
2
|
|
|
|
3
|
|
|
// BlackList contains ignored guilds and users |
|
|
|
|
4
|
|
|
type BlackListStruct struct { |
5
|
|
|
Guilds []string |
6
|
|
|
Users []string |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
// CheckGuild returns true if guild in blacklist |
10
|
|
|
func (b BlackListStruct) CheckGuild(id string) bool { |
11
|
|
|
for _,g := range b.Guilds { |
12
|
|
|
if g == id { |
13
|
|
|
return true |
14
|
|
|
} |
15
|
|
|
} |
16
|
|
|
return false |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
// CheckUser returns true if user in blacklist |
20
|
|
|
func (b BlackListStruct) CheckUser(id string) bool { |
21
|
|
|
for _,g := range b.Users { |
22
|
|
|
if g == id { |
23
|
|
|
return true |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
return false |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// BlacklistAddGuild adds guild in blacklist |
30
|
|
|
func (ctx *Context) BlacklistAddGuild(id string) { |
31
|
|
|
ctx.BlackList.Guilds = append(ctx.BlackList.Guilds, id) |
32
|
|
|
ctx.DB.AddBlacklistGuild(id) |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// BlacklistAddUser adds user in blacklist |
36
|
|
|
func (ctx *Context) BlacklistAddUser(id string) { |
37
|
|
|
ctx.BlackList.Users = append(ctx.BlackList.Users, id) |
38
|
|
|
ctx.DB.AddBlacklistUser(id) |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// BlacklistRemoveGuild removes guild from blacklist |
42
|
|
|
func (ctx *Context) BlacklistRemoveGuild(id string) { |
43
|
|
|
var newArray []string |
44
|
|
|
for _, g := range ctx.BlackList.Guilds { |
45
|
|
|
if g != id { |
46
|
|
|
newArray = append(newArray, g) |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
ctx.BlackList.Guilds = newArray |
50
|
|
|
ctx.DB.RemoveBlacklistGuild(id) |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// BlacklistRemoveUser removes user from blacklist |
54
|
|
|
func (ctx *Context) BlacklistRemoveUser(id string) { |
55
|
|
|
var newArray []string |
56
|
|
|
for _, u := range ctx.BlackList.Users { |
57
|
|
|
if u != id { |
58
|
|
|
newArray = append(newArray, u) |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
ctx.BlackList.Users = newArray |
62
|
|
|
ctx.DB.RemoveBlacklistUser(id) |
63
|
|
|
} |