nechotron/command.go

38 lines
733 B
Go
Raw Normal View History

package nechotron
2023-01-24 00:37:08 +03:00
import (
"fmt"
"strings"
)
type Command struct {
Body string
IsAdminOnly bool
2023-01-24 00:37:08 +03:00
Description string
}
2023-01-24 00:37:08 +03:00
func NewCommand(body string, desc string, isAdminOnly bool) *Command {
return &Command{
Body: body,
IsAdminOnly: isAdminOnly,
2023-01-24 00:37:08 +03:00
Description: desc,
}
}
func (c *Command) String() string {
return "/" + c.Body
}
func (c *Command) Param(text string) string {
return strings.TrimPrefix(text, "/"+c.Body+" ")
}
2023-01-24 00:37:08 +03:00
func MakeCommandList(commands []*Command, format string) string {
result := ""
for _, command := range commands {
result += fmt.Sprintf(format, command.String(), command.Description)
}
return result
}
// func HandleCommand(command *Command, handler cmdFunc) (bool, error)