fix(config): a role can be present twice
This commit is contained in:
parent
bde93e6b80
commit
fc151a9cee
2 changed files with 13 additions and 4 deletions
|
@ -86,12 +86,21 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
// add or delete or edit
|
||||
switch ts {
|
||||
case "add":
|
||||
for _, r := range cfg.XpRoles {
|
||||
if r.RoleID == role.ID {
|
||||
err := resp.Message("Le rôle est déjà présent dans la config").Send()
|
||||
if err != nil {
|
||||
utils.SendAlert("commands/config.go - Role already in config", err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
cfg.XpRoles = append(cfg.XpRoles, config.XpRole{
|
||||
XP: exp,
|
||||
RoleID: role.ID,
|
||||
})
|
||||
case "del":
|
||||
_, r := cfg.FindXpRole(exp, role.ID)
|
||||
_, r := cfg.FindXpRole(role.ID)
|
||||
if r == nil {
|
||||
err := resp.Message("Le rôle n'a pas été trouvé dans la config.").Send()
|
||||
if err != nil {
|
||||
|
@ -101,7 +110,7 @@ func ConfigXP(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||
}
|
||||
gokord.DB.Delete(r)
|
||||
case "edit":
|
||||
pos, r := cfg.FindXpRole(exp, role.ID)
|
||||
pos, r := cfg.FindXpRole(role.ID)
|
||||
if r == nil {
|
||||
err := resp.Message("Le rôle n'a pas été trouvé dans la config.").Send()
|
||||
if err != nil {
|
||||
|
|
|
@ -32,9 +32,9 @@ func (cfg *GuildConfig) Save() {
|
|||
gokord.DB.Save(cfg)
|
||||
}
|
||||
|
||||
func (cfg *GuildConfig) FindXpRole(xp uint, roleID string) (int, *XpRole) {
|
||||
func (cfg *GuildConfig) FindXpRole(roleID string) (int, *XpRole) {
|
||||
for i, r := range cfg.XpRoles {
|
||||
if r.XP == xp && r.RoleID == roleID {
|
||||
if r.RoleID == roleID {
|
||||
return i, &r
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue