From e75100d985897ef3eccf2a20c25276136bb65c34 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 28 May 2021 19:46:05 +0100 Subject: [PATCH] h --- features/handlers.go | 5 ----- features/misc.go | 24 ++++++++++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/features/handlers.go b/features/handlers.go index 86dec91..40b73cc 100644 --- a/features/handlers.go +++ b/features/handlers.go @@ -68,11 +68,6 @@ func (f *Features) RegisterHandlers() { f.RegisterCommand("saveconfig", "Save Configuration to Disk", true, f.handleSaveConfig) f.RegisterCommand("reloadconfig", "Reload Configuration", true, f.handleReloadConfig) 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 { diff --git a/features/misc.go b/features/misc.go index cf0cf0e..3b56879 100644 --- a/features/misc.go +++ b/features/misc.go @@ -4,14 +4,16 @@ import ( "encoding/json" "errors" "fmt" - "github.com/bwmarrin/discordgo" - "github.com/foxtrot/scuzzy/models" "io/ioutil" "os" "reflect" + "sort" "strconv" "strings" "time" + + "github.com/bwmarrin/discordgo" + "github.com/foxtrot/scuzzy/models" ) 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 { + 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" - for _, command := range f.ScuzzyCommandsByIndex { + for _, k := range keys { + command := f.ScuzzyCommandsByIndex[k] + if !command.AdminOnly && command.Description != "" { 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) { desc += "\n" desc += "**Admin Commands**\n" - for _, command := range f.ScuzzyCommandsByIndex { + for _, k := range keys { + command := f.ScuzzyCommandsByIndex[k] + if command.AdminOnly { desc += "`" + command.Name + "` - " + command.Description + "\n" }