|
@@ -20,6 +20,102 @@ func (r *Router) helpCommandHandler(s *discordgo.Session, m *discordgo.Message,
|
|
|
displayPrefix = fmt.Sprintf("@%s ", s.State.User.Username)
|
|
|
}
|
|
|
|
|
|
+ maxDisplayLen := 0
|
|
|
+ cmdmap := make(map[string]*route)
|
|
|
+ catMap := make(map[string][]string)
|
|
|
+ var cats []string
|
|
|
+
|
|
|
+ for _, v := range r.categories {
|
|
|
+ keys := make([]string, 0, len(r.routes))
|
|
|
+ for _, route := range r.routes {
|
|
|
+ if route.CategoryID == v.ID {
|
|
|
+ l := len(route.Usage) // TODO: Add the +args part :)
|
|
|
+ if l > maxDisplayLen {
|
|
|
+ maxDisplayLen = l
|
|
|
+ }
|
|
|
+ cmdmap[route.Name] = route
|
|
|
+ keys = append(keys, route.Name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(keys) > 0 {
|
|
|
+ sort.Strings(keys)
|
|
|
+ catMap[v.Description] = keys
|
|
|
+ cats = append(cats, v.Description)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ keys := make([]string, 0, len(r.routes))
|
|
|
+ for _, route := range r.routes {
|
|
|
+ if route.CategoryID == 0 {
|
|
|
+ l := len(route.Usage) // TODO: Add the +args part :)
|
|
|
+ if l > maxDisplayLen {
|
|
|
+ maxDisplayLen = l
|
|
|
+ }
|
|
|
+ cmdmap[route.Name] = route
|
|
|
+
|
|
|
+ if route.Name == "help" || route.Name == "about" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ keys = append(keys, route.Name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ v, ok := cmdmap["help"]
|
|
|
+ if ok {
|
|
|
+ keys = append([]string{v.Name}, keys...)
|
|
|
+ }
|
|
|
+
|
|
|
+ v, ok = cmdmap["about"]
|
|
|
+ if ok {
|
|
|
+ keys = append([]string{v.Name}, keys...)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(keys) > 0 {
|
|
|
+ sort.Strings(keys)
|
|
|
+ catMap[""] = keys
|
|
|
+ cats = append(cats, "")
|
|
|
+ }
|
|
|
+
|
|
|
+ maxDisplayLen = maxDisplayLen + 3
|
|
|
+
|
|
|
+ // TODO: Learn more link needs to be configurable
|
|
|
+ resp := "```autoit\n"
|
|
|
+
|
|
|
+ // Add sorted result to help msg
|
|
|
+ for _, catKey := range cats {
|
|
|
+ if catKey != "" {
|
|
|
+ resp += fmt.Sprintf("\n%s\n", catKey)
|
|
|
+ } else {
|
|
|
+ resp += fmt.Sprint("\n\n")
|
|
|
+ }
|
|
|
+
|
|
|
+ routes := catMap[catKey]
|
|
|
+ for _, routeKey := range routes {
|
|
|
+ route := cmdmap[routeKey]
|
|
|
+ resp += fmt.Sprintf("%s%-"+strconv.Itoa(maxDisplayLen)+"s # %s\n", displayPrefix, route.Usage, route.Description)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resp += "```\n"
|
|
|
+ s.ChannelMessageSend(m.ChannelID, resp)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (r *Router) helpCommandHandlerOld(s *discordgo.Session, m *discordgo.Message, ctx *Context) {
|
|
|
+ displayPrefix := ""
|
|
|
+
|
|
|
+ switch ctx.Method {
|
|
|
+ case DirectMethod:
|
|
|
+ displayPrefix = ""
|
|
|
+ case PrefixMethod:
|
|
|
+ displayPrefix = r.prefix
|
|
|
+ case MentionMethod:
|
|
|
+ displayPrefix = fmt.Sprintf("@%s ", s.State.User.Username)
|
|
|
+ }
|
|
|
+
|
|
|
// Sort commands
|
|
|
maxDisplayLen := 0
|
|
|
keys := make([]string, 0, len(r.routes))
|
|
@@ -32,7 +128,7 @@ func (r *Router) helpCommandHandler(s *discordgo.Session, m *discordgo.Message,
|
|
|
}
|
|
|
|
|
|
// Calculate the max length of command+args string
|
|
|
- l := len(v.Name) // TODO: Add the +args part :)
|
|
|
+ l := len(v.Usage) // TODO: Add the +args part :)
|
|
|
if l > maxDisplayLen {
|
|
|
maxDisplayLen = l
|
|
|
}
|
|
@@ -65,7 +161,7 @@ func (r *Router) helpCommandHandler(s *discordgo.Session, m *discordgo.Message,
|
|
|
// Add sorted result to help msg
|
|
|
for _, k := range keys {
|
|
|
v := cmdmap[k]
|
|
|
- resp += fmt.Sprintf("%s%-"+strconv.Itoa(maxDisplayLen)+"s # %s\n", displayPrefix, v.Name, v.Description)
|
|
|
+ resp += fmt.Sprintf("%s%-"+strconv.Itoa(maxDisplayLen)+"s # %s\n", displayPrefix, v.Usage, v.Description)
|
|
|
}
|
|
|
|
|
|
resp += "```\n"
|