This commit is contained in:
parent
9e1702fa4b
commit
8256b596ff
1
guild.go
1
guild.go
@ -25,4 +25,5 @@ type GuildService interface {
|
||||
UpdateRole(r Role) (Role, error)
|
||||
DeleteRole(r Role) error
|
||||
GetOrCreateGuild(id string) (Guild, error)
|
||||
CreateOrUpdateRole(r Role) (Role, error)
|
||||
}
|
||||
|
||||
@ -111,3 +111,9 @@ func (s guildService) GetOrCreateGuild(id string) (geeksbot.Guild, error) {
|
||||
}
|
||||
return guild, err
|
||||
}
|
||||
|
||||
func (s guildService) CreateOrUpdateRole(r geeksbot.Role) (geeksbot.Role, error) {
|
||||
queryString := "INSERT INTO roles (id, role_type, guild_id) VALUES ($1, $2, $3)"
|
||||
_, err := s.db.Exec(queryString, r.ID, r.RoleType, r.Guild.ID)
|
||||
return r, err
|
||||
}
|
||||
|
||||
47
internal/exts/guild/roles.go
Normal file
47
internal/exts/guild/roles.go
Normal file
@ -0,0 +1,47 @@
|
||||
package guild
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
"github.com/dustinpianalto/geeksbot/internal/discord_utils"
|
||||
"github.com/dustinpianalto/geeksbot/internal/services"
|
||||
)
|
||||
|
||||
var AddModeratorRoleCommand = &disgoman.Command{
|
||||
Name: "addMod",
|
||||
Aliases: []string{"addModerator", "addModRole"},
|
||||
Description: "Add a role which is allowed to run moderator commands",
|
||||
OwnerOnly: false,
|
||||
Hidden: false,
|
||||
RequiredPermissions: disgoman.PermissionManageServer,
|
||||
Invoke: addModeratorRoleCommandFunc,
|
||||
}
|
||||
|
||||
func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
|
||||
var count int
|
||||
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 ctx.Message.MentionRoles {
|
||||
_, err := services.GuildService.CreateRole(geeksbot.Role{
|
||||
ID: id,
|
||||
RoleType: "moderator",
|
||||
Guild: guild,
|
||||
})
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem adding <@&%s>", id), err)
|
||||
continue
|
||||
}
|
||||
count++
|
||||
_, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as a moderator role.", id))
|
||||
}
|
||||
} else {
|
||||
_, _ = ctx.Send("Please include at least one role to make a moderator role.")
|
||||
}
|
||||
}
|
||||
@ -24,5 +24,6 @@ func AddCommandHandlers(g *disgoman.CommandManager) {
|
||||
_ = g.AddCommand(utils.PingCommand)
|
||||
_ = g.AddCommand(guild.AddPrefixCommand)
|
||||
_ = g.AddCommand(guild.RemovePrefixCommand)
|
||||
_ = g.AddCommand(guild.AddModeratorRoleCommand)
|
||||
_ = g.AddCommand(requests.RequestCommand)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user