|
|
|
@ -3,6 +3,7 @@ package telegram
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
"sort"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
@ -146,6 +147,21 @@ func GetCommand(typ CommandType, cmd string) (command, bool) {
|
|
|
|
|
return command, ok
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SortedCommandKeys sorts a slice with command keys
|
|
|
|
|
func SortedCommandKeys(commandMap map[string]command) []string {
|
|
|
|
|
keys := make([]string, len(commandMap))
|
|
|
|
|
|
|
|
|
|
i := 0
|
|
|
|
|
for k := range commandMap {
|
|
|
|
|
keys[i] = k
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sort.Strings(keys)
|
|
|
|
|
|
|
|
|
|
return keys
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandToHelpString builds a text description of a command
|
|
|
|
|
func CommandToHelpString(name string, cmd command) string {
|
|
|
|
|
var str strings.Builder
|
|
|
|
@ -175,7 +191,8 @@ func helpString(typ CommandType) string {
|
|
|
|
|
commandMap := GetCommands(typ)
|
|
|
|
|
|
|
|
|
|
str.WriteString("Available commands:\n")
|
|
|
|
|
for name, command := range commandMap {
|
|
|
|
|
for _, name := range SortedCommandKeys(commandMap) {
|
|
|
|
|
command := commandMap[name]
|
|
|
|
|
str.WriteString(CommandToHelpString(name, command))
|
|
|
|
|
str.WriteString("\n")
|
|
|
|
|
}
|
|
|
|
|