Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71aac148e0 | ||
|
|
132bf94332 | ||
|
|
964be05c48 | ||
|
|
4895294969 | ||
|
|
9d0d1ddd56 |
@@ -113,8 +113,8 @@ func (s guildService) GetOrCreateGuild(id string) (geeksbot.Guild, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s guildService) CreateOrUpdateRole(r geeksbot.Role) (geeksbot.Role, error) {
|
func (s guildService) CreateOrUpdateRole(r geeksbot.Role) (geeksbot.Role, error) {
|
||||||
role, err := s.Role(r.ID)
|
role, err := s.CreateRole(r)
|
||||||
if err.Error() == `pq: duplicate key value violates unique constraint "roles_pkey"` {
|
if err != nil && err.Error() == `pq: duplicate key value violates unique constraint "roles_pkey"` {
|
||||||
role, err = s.UpdateRole(r)
|
role, err = s.UpdateRole(r)
|
||||||
}
|
}
|
||||||
return role, err
|
return role, err
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/dustinpianalto/geeksbot"
|
"github.com/dustinpianalto/geeksbot"
|
||||||
"github.com/dustinpianalto/geeksbot/internal/discord_utils"
|
"github.com/dustinpianalto/geeksbot/internal/discord_utils"
|
||||||
"github.com/dustinpianalto/geeksbot/internal/services"
|
"github.com/dustinpianalto/geeksbot/internal/services"
|
||||||
|
"github.com/dustinpianalto/geeksbot/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AddModeratorRoleCommand = &disgoman.Command{
|
var AddModeratorRoleCommand = &disgoman.Command{
|
||||||
@@ -37,6 +38,10 @@ func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
|
|||||||
if _, ok := added[id]; ok {
|
if _, ok := added[id]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if _, err = ctx.Session.State.Role(ctx.Guild.ID, id); err != nil {
|
||||||
|
_, _ = ctx.Send(fmt.Sprintf("%s does not reference a valid role for this guild.", id))
|
||||||
|
continue
|
||||||
|
}
|
||||||
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
|
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
|
||||||
ID: id,
|
ID: id,
|
||||||
RoleType: "moderator",
|
RoleType: "moderator",
|
||||||
@@ -50,7 +55,7 @@ func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
|
|||||||
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))
|
_, _ = ctx.Send(fmt.Sprintf("Added %d moderator %s.", count, utils.PluralizeString("role", 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.")
|
||||||
}
|
}
|
||||||
@@ -83,6 +88,10 @@ func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) {
|
|||||||
if _, ok := added[id]; ok {
|
if _, ok := added[id]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if _, err = ctx.Session.State.Role(ctx.Guild.ID, id); err != nil {
|
||||||
|
_, _ = ctx.Send(fmt.Sprintf("%s does not reference a valid role for this guild.", id))
|
||||||
|
continue
|
||||||
|
}
|
||||||
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
|
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
|
||||||
ID: id,
|
ID: id,
|
||||||
RoleType: "admin",
|
RoleType: "admin",
|
||||||
@@ -96,8 +105,67 @@ func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) {
|
|||||||
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))
|
_, _ = ctx.Send(fmt.Sprintf("Added %d admin %s.", count, utils.PluralizeString("role", 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.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var RemoveModRoleCommand = &disgoman.Command{
|
||||||
|
Name: "removeMod",
|
||||||
|
Aliases: []string{"removeModeratorRole", "removeModRole", "removeAdmin", "removeAdminRole"},
|
||||||
|
Description: "Remove a role or several roles from the moderator or admin list",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: disgoman.PermissionManageServer,
|
||||||
|
Invoke: removeModRoleCommandFunc,
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeModRoleCommandFunc(ctx disgoman.Context, args []string) {
|
||||||
|
var count int
|
||||||
|
added := make(map[string]bool)
|
||||||
|
guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID)
|
||||||
|
if err != nil {
|
||||||
|
discord_utils.SendErrorMessage(ctx, "Something went wrong getting the guild", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
roles := append(args, ctx.Message.MentionRoles...)
|
||||||
|
if len(roles) > 0 {
|
||||||
|
for _, id := range roles {
|
||||||
|
if strings.HasPrefix(id, "<@&") && strings.HasSuffix(id, ">") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := added[id]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err = ctx.Session.State.Role(ctx.Guild.ID, 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{
|
||||||
|
ID: id,
|
||||||
|
RoleType: "normal",
|
||||||
|
Guild: guild,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
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 %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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,5 +26,6 @@ func AddCommandHandlers(g *disgoman.CommandManager) {
|
|||||||
_ = g.AddCommand(guild.RemovePrefixCommand)
|
_ = g.AddCommand(guild.RemovePrefixCommand)
|
||||||
_ = g.AddCommand(guild.AddModeratorRoleCommand)
|
_ = g.AddCommand(guild.AddModeratorRoleCommand)
|
||||||
_ = g.AddCommand(guild.AddAdminRoleCommand)
|
_ = g.AddCommand(guild.AddAdminRoleCommand)
|
||||||
|
_ = g.AddCommand(guild.RemoveModRoleCommand)
|
||||||
_ = g.AddCommand(requests.RequestCommand)
|
_ = g.AddCommand(requests.RequestCommand)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,3 +12,10 @@ func RemoveDuplicateStrings(s []string) []string {
|
|||||||
}
|
}
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PluralizeString(s string, i int) string {
|
||||||
|
if i == 1 {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return s + "s"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user