Passed
Push — master ( d15815...179a5e )
by Viktor
01:44
created

bot/role.go   A

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 25
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A bot.*Context.IsAdmin 0 5 2
B bot.*Context.GetRoles 0 14 7
A bot.*UserRoles.ExistsName 0 7 4
1
package bot
2
3
import (
4
	"fmt"
5
6
	"github.com/bwmarrin/discordgo"
7
)
8
9
// UserRoles struct with array of user roles in guild
10
type UserRoles struct {
11
	Roles []*discordgo.Role
12
}
13
14
func (ctx *Context) IsAdmin() bool {
0 ignored issues
show
introduced by
exported method Context.IsAdmin should have comment or be unexported
Loading history...
15
	if ctx.User.ID == ctx.Conf.General.AdminID {
16
		return true
17
	}
18
	return false
19
}
20
21
// GetRole returns UserRoles struct pointer
0 ignored issues
show
introduced by
comment on exported method Context.GetRoles should be of the form "GetRoles ..."
Loading history...
22
func (ctx *Context) GetRoles() *UserRoles {
23
	var userRoles = new(UserRoles)
24
	memb, err := ctx.Discord.GuildMember(ctx.Guild.ID, ctx.User.ID)
25
	if err != nil {
26
		fmt.Println("Getting member error: " + err.Error())
27
	}
28
	for _, grole := range ctx.Guild.Roles {
29
		for _, urole := range memb.Roles {
30
			if grole.ID == urole {
31
				userRoles.Roles = append(userRoles.Roles, grole)
32
			}
33
		}
34
	}
35
	return userRoles
36
}
37
38
// ExistsName checks if user role nema exists on user
39
func (r *UserRoles) ExistsName(name string) bool {
40
	for _, val := range r.Roles {
41
		if val.Name == name {
42
			return true
43
		}
44
	}
45
	return false
46
}
47