Passed
Push — master ( 5ddae7...29f8b3 )
by Viktor
01:35
created

bot.BlackListStruct.CheckUser   A

Complexity

Conditions 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
package bot
2
3
// BlackList contains ignored guilds and users
0 ignored issues
show
introduced by
comment on exported type BlackListStruct should be of the form "BlackListStruct ..." (with optional leading article)
Loading history...
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
}