This commit is contained in:
parent
cdbeac195f
commit
53276a1442
@ -113,7 +113,9 @@ 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) {
|
||||||
queryString := "INSERT INTO roles (id, role_type, guild_id) VALUES ($1, $2, $3)"
|
role, err := s.Role(r.ID)
|
||||||
_, err := s.db.Exec(queryString, r.ID, r.RoleType, r.Guild.ID)
|
if err.Error() == `pq: duplicate key value violates unique constraint "roles_pkey"` {
|
||||||
return r, err
|
role, err = s.UpdateRole(r)
|
||||||
|
}
|
||||||
|
return role, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,3 +45,40 @@ func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
|
|||||||
_, _ = 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.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var AddAdminRoleCommand = &disgoman.Command{
|
||||||
|
Name: "addAdmin",
|
||||||
|
Aliases: []string{"addAdminRole"},
|
||||||
|
Description: "Add a role which is allowed to run admin commands",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: disgoman.PermissionManageServer,
|
||||||
|
Invoke: addAdminRoleCommandFunc,
|
||||||
|
}
|
||||||
|
|
||||||
|
func addAdminRoleCommandFunc(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 roles {
|
||||||
|
_, err := services.GuildService.CreateRole(geeksbot.Role{
|
||||||
|
ID: id,
|
||||||
|
RoleType: "admin",
|
||||||
|
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 an admin role.", id))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_, _ = ctx.Send("Please include at least one role to make an admin role.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -25,5 +25,6 @@ func AddCommandHandlers(g *disgoman.CommandManager) {
|
|||||||
_ = g.AddCommand(guild.AddPrefixCommand)
|
_ = g.AddCommand(guild.AddPrefixCommand)
|
||||||
_ = g.AddCommand(guild.RemovePrefixCommand)
|
_ = g.AddCommand(guild.RemovePrefixCommand)
|
||||||
_ = g.AddCommand(guild.AddModeratorRoleCommand)
|
_ = g.AddCommand(guild.AddModeratorRoleCommand)
|
||||||
|
_ = g.AddCommand(guild.AddAdminRoleCommand)
|
||||||
_ = g.AddCommand(requests.RequestCommand)
|
_ = g.AddCommand(requests.RequestCommand)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user