From 71aac148e07704eaba062776658ab42fa955f4a6 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Tue, 26 Jan 2021 00:08:20 -0900 Subject: [PATCH] remove mod/admin role command --- internal/exts/guild/roles.go | 18 +++++++++++++----- internal/utils/utils.go | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/internal/exts/guild/roles.go b/internal/exts/guild/roles.go index 7d5a6ce..7a90f0a 100644 --- a/internal/exts/guild/roles.go +++ b/internal/exts/guild/roles.go @@ -8,6 +8,7 @@ import ( "github.com/dustinpianalto/geeksbot" "github.com/dustinpianalto/geeksbot/internal/discord_utils" "github.com/dustinpianalto/geeksbot/internal/services" + "github.com/dustinpianalto/geeksbot/internal/utils" ) var AddModeratorRoleCommand = &disgoman.Command{ @@ -54,7 +55,7 @@ func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) { count++ _, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as a moderator role.", id)) } - _, _ = ctx.Send(fmt.Sprintf("Added %d moderator roles.", count)) + _, _ = ctx.Send(fmt.Sprintf("Added %d moderator %s.", count, utils.PluralizeString("role", count))) } else { _, _ = ctx.Send("Please include at least one role to make a moderator role.") } @@ -104,7 +105,7 @@ func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) { count++ _, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as an admin role.", id)) } - _, _ = ctx.Send(fmt.Sprintf("Added %d admin roles.", count)) + _, _ = ctx.Send(fmt.Sprintf("Added %d admin %s.", count, utils.PluralizeString("role", count))) } else { _, _ = ctx.Send("Please include at least one role to make an admin role.") } @@ -138,9 +139,16 @@ func removeModRoleCommandFunc(ctx disgoman.Context, args []string) { continue } if _, err = ctx.Session.State.Role(ctx.Guild.ID, id); err != nil { - if _, err := services.GuildService.Role(id); err != nil { + if r, err := services.GuildService.Role(id); err != nil { _, _ = ctx.Send(fmt.Sprintf("%s does not reference a valid role for this guild.", id)) continue + } else { + err = services.GuildService.DeleteRole(r) + if err != nil { + discord_utils.SendErrorMessage(ctx, "Something went wrong deleting the role", err) + } + _, _ = ctx.Send(fmt.Sprintf("Deleted <@&%s> as a no longer a valid role.", id)) + continue } } _, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{ @@ -149,14 +157,14 @@ func removeModRoleCommandFunc(ctx disgoman.Context, args []string) { Guild: guild, }) if err != nil { - discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem adding <@&%s>", id), err) + discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem updating <@&%s>", id), err) continue } added[id] = true count++ _, _ = ctx.Send(fmt.Sprintf("Set <@&%s> as a normal role.", id)) } - _, _ = ctx.Send(fmt.Sprintf("Set %d roles to normal.", count)) + _, _ = ctx.Send(fmt.Sprintf("Set %d %s to normal.", count, utils.PluralizeString("role", count))) } else { _, _ = ctx.Send("Please include at least one role to remove from the moderator or admin lists.") } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 8b8b330..3b5d589 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -12,3 +12,10 @@ func RemoveDuplicateStrings(s []string) []string { } return o } + +func PluralizeString(s string, i int) string { + if i == 1 { + return s + } + return s + "s" +}