Features: Add the ability for Admins to create user joinable roles.

master
Marc Egerton 2020-09-18 12:54:07 +01:00
parent fc445de871
commit 8cc0c09db1
No known key found for this signature in database
GPG Key ID: A11F9CA36DF845E0
3 changed files with 36 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package features
import (
"errors"
discordgo "github.com/bwmarrin/discord.go"
"github.com/foxtrot/scuzzy/models"
"strings"
)
@ -114,3 +116,35 @@ func (f *Features) handleLeaveCustomRole(s *discordgo.Session, m *discordgo.Mess
return nil
}
func (f *Features) handleAddCustomRole(s *discordgo.Session, m *discordgo.MessageCreate) error {
var err error
if !f.Permissions.CheckAdminRole(m.Member) {
return errors.New("You do not have permissions to use that command.")
}
userInput := strings.Split(m.Content, " ")
if len(userInput) < 3 {
return errors.New("Expected Arguments: short_name role_id")
}
shortName := userInput[1]
shortName = strings.ToLower(shortName)
roleID := userInput[2]
customRole := models.CustomRole{
Name: "",
ShortName: shortName,
ID: roleID,
}
f.Config.CustomRoles = append(f.Config.CustomRoles, customRole)
err = f.handleSaveConfig(s, m)
if err != nil {
return err
}
return nil
}

View File

@ -56,6 +56,7 @@ func (f *Features) RegisterHandlers() {
f.RegisterCommand("getconfig", f.handleGetConfig)
f.RegisterCommand("saveconfig", f.handleSaveConfig)
f.RegisterCommand("reloadconfig", f.handleReloadConfig)
f.RegisterCommand("addrole", f.handleAddCustomRole)
}
func (f *Features) ProcessCommand(s *discordgo.Session, m *discordgo.MessageCreate) error {

View File

@ -326,6 +326,7 @@ func (f *Features) handleHelp(s *discordgo.Session, m *discordgo.MessageCreate)
desc += "`getconfig` - View the runtime configuration\n"
desc += "`reloadconfig` - Reload configuration from disk\n"
desc += "`saveconfig` - Save the runtime configuration to disk\n"
desc += "`addrole` - Add a user joinable role\n"
}
desc += "\n\nAll commands are prefixed with `" + f.Config.CommandKey + "`\n"