Marc 2021-05-28 19:46:05 +01:00
parent 1538b3b65c
commit e75100d985
No known key found for this signature in database
GPG Key ID: 0657563F705ACAAE
2 changed files with 20 additions and 9 deletions

View File

@ -68,11 +68,6 @@ func (f *Features) RegisterHandlers() {
f.RegisterCommand("saveconfig", "Save Configuration to Disk", true, f.handleSaveConfig) f.RegisterCommand("saveconfig", "Save Configuration to Disk", true, f.handleSaveConfig)
f.RegisterCommand("reloadconfig", "Reload Configuration", true, f.handleReloadConfig) f.RegisterCommand("reloadconfig", "Reload Configuration", true, f.handleReloadConfig)
f.RegisterCommand("addrole", "Add a joinable role", true, f.handleAddCustomRole) f.RegisterCommand("addrole", "Add a joinable role", true, f.handleAddCustomRole)
sort.Slice(f.ScuzzyCommandsByIndex, func(i, j int) bool {
return f.ScuzzyCommandsByIndex[i].Index > f.ScuzzyCommandsByIndex[j].Index
})
} }
func (f *Features) ProcessCommand(s *discordgo.Session, m *discordgo.MessageCreate) error { func (f *Features) ProcessCommand(s *discordgo.Session, m *discordgo.MessageCreate) error {

View File

@ -4,14 +4,16 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/bwmarrin/discordgo"
"github.com/foxtrot/scuzzy/models"
"io/ioutil" "io/ioutil"
"os" "os"
"reflect" "reflect"
"sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/bwmarrin/discordgo"
"github.com/foxtrot/scuzzy/models"
) )
func (f *Features) handleSetConfig(s *discordgo.Session, m *discordgo.MessageCreate) error { func (f *Features) handleSetConfig(s *discordgo.Session, m *discordgo.MessageCreate) error {
@ -288,8 +290,20 @@ func (f *Features) handleInfo(s *discordgo.Session, m *discordgo.MessageCreate)
} }
func (f *Features) handleHelp(s *discordgo.Session, m *discordgo.MessageCreate) error { func (f *Features) handleHelp(s *discordgo.Session, m *discordgo.MessageCreate) error {
keys := make([]int, 0, len(f.ScuzzyCommands))
for _, cmd := range f.ScuzzyCommands {
keys = append(keys, cmd.Index)
}
sort.Ints(keys)
for _, k := range keys {
fmt.Println(k, f.ScuzzyCommandsByIndex[k])
}
desc := "**Available Commands**\n" desc := "**Available Commands**\n"
for _, command := range f.ScuzzyCommandsByIndex { for _, k := range keys {
command := f.ScuzzyCommandsByIndex[k]
if !command.AdminOnly && command.Description != "" { if !command.AdminOnly && command.Description != "" {
desc += "`" + command.Name + "` - " + command.Description + "\n" desc += "`" + command.Name + "` - " + command.Description + "\n"
} }
@ -298,7 +312,9 @@ func (f *Features) handleHelp(s *discordgo.Session, m *discordgo.MessageCreate)
if f.Permissions.CheckAdminRole(m.Member) { if f.Permissions.CheckAdminRole(m.Member) {
desc += "\n" desc += "\n"
desc += "**Admin Commands**\n" desc += "**Admin Commands**\n"
for _, command := range f.ScuzzyCommandsByIndex { for _, k := range keys {
command := f.ScuzzyCommandsByIndex[k]
if command.AdminOnly { if command.AdminOnly {
desc += "`" + command.Name + "` - " + command.Description + "\n" desc += "`" + command.Name + "` - " + command.Description + "\n"
} }