fix role commands

development v0.0.60
DustyP 5 years ago
parent 53276a1442
commit a587a64bd9

@ -2,6 +2,7 @@ package guild
import ( import (
"fmt" "fmt"
"strings"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/geeksbot" "github.com/dustinpianalto/geeksbot"
@ -21,6 +22,7 @@ var AddModeratorRoleCommand = &disgoman.Command{
func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) { func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
var count int var count int
added := make(map[string]bool)
guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID) guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID)
if err != nil { if err != nil {
discord_utils.SendErrorMessage(ctx, "Something went wrong getting the guild", err) discord_utils.SendErrorMessage(ctx, "Something went wrong getting the guild", err)
@ -29,7 +31,13 @@ func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
roles := append(args, ctx.Message.MentionRoles...) roles := append(args, ctx.Message.MentionRoles...)
if len(roles) > 0 { if len(roles) > 0 {
for _, id := range roles { for _, id := range roles {
_, err := services.GuildService.CreateRole(geeksbot.Role{ if strings.HasPrefix(id, "<@&") && strings.HasSuffix(id, ">") {
continue
}
if _, ok := added[id]; ok {
continue
}
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
ID: id, ID: id,
RoleType: "moderator", RoleType: "moderator",
Guild: guild, Guild: guild,
@ -38,9 +46,11 @@ func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem adding <@&%s>", id), err) discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem adding <@&%s>", id), err)
continue continue
} }
added[id] = true
count++ count++
_, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as a moderator role.", id)) _, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as a moderator role.", id))
} }
_, _ = ctx.Send(fmt.Sprintf("Added %d moderator roles.", count))
} else { } else {
_, _ = ctx.Send("Please include at least one role to make a moderator role.") _, _ = ctx.Send("Please include at least one role to make a moderator role.")
} }
@ -58,6 +68,7 @@ var AddAdminRoleCommand = &disgoman.Command{
func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) { func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) {
var count int var count int
added := make(map[string]bool)
guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID) guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID)
if err != nil { if err != nil {
discord_utils.SendErrorMessage(ctx, "Something went wrong getting the guild", err) discord_utils.SendErrorMessage(ctx, "Something went wrong getting the guild", err)
@ -66,7 +77,13 @@ func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) {
roles := append(args, ctx.Message.MentionRoles...) roles := append(args, ctx.Message.MentionRoles...)
if len(roles) > 0 { if len(roles) > 0 {
for _, id := range roles { for _, id := range roles {
_, err := services.GuildService.CreateRole(geeksbot.Role{ if strings.HasPrefix(id, "<@&") && strings.HasSuffix(id, ">") {
continue
}
if _, ok := added[id]; ok {
continue
}
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
ID: id, ID: id,
RoleType: "admin", RoleType: "admin",
Guild: guild, Guild: guild,
@ -75,9 +92,11 @@ func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem adding <@&%s>", id), err) discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem adding <@&%s>", id), err)
continue continue
} }
added[id] = true
count++ count++
_, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as an admin role.", id)) _, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as an admin role.", id))
} }
_, _ = ctx.Send(fmt.Sprintf("Added %d admin roles.", count))
} else { } else {
_, _ = ctx.Send("Please include at least one role to make an admin role.") _, _ = ctx.Send("Please include at least one role to make an admin role.")
} }

Loading…
Cancel
Save