59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
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()
|
|
}
|