Fixed bot verbosity

This commit is contained in:
Stephan D
2026-03-05 11:02:30 +01:00
parent 364731a8c7
commit d1e47841cc
5 changed files with 151 additions and 47 deletions

View File

@@ -0,0 +1,58 @@
package bot
import "strings"
type Command string
const (
CommandStart Command = "start"
CommandFund Command = "fund"
CommandWithdraw Command = "withdraw"
CommandConfirm Command = "confirm"
CommandCancel Command = "cancel"
)
var supportedCommands = []Command{
CommandStart,
CommandFund,
CommandWithdraw,
CommandConfirm,
CommandCancel,
}
func (c Command) Slash() string {
name := strings.TrimSpace(string(c))
if name == "" {
return ""
}
return "/" + name
}
func parseCommand(text string) Command {
text = strings.TrimSpace(text)
if !strings.HasPrefix(text, "/") {
return ""
}
token := text
if idx := strings.IndexAny(token, " \t\n\r"); idx >= 0 {
token = token[:idx]
}
token = strings.TrimPrefix(token, "/")
if idx := strings.Index(token, "@"); idx >= 0 {
token = token[:idx]
}
return Command(strings.ToLower(strings.TrimSpace(token)))
}
func supportedCommandsMessage() string {
lines := make([]string, 0, len(supportedCommands)+1)
lines = append(lines, "Supported commands:")
for _, cmd := range supportedCommands {
lines = append(lines, cmd.Slash())
}
return strings.Join(lines, "\n")
}
func confirmationCommandsMessage() string {
return "Confirm operation?\n\n" + CommandConfirm.Slash() + "\n" + CommandCancel.Slash()
}