2023-01-22 23:54:54 +03:00
|
|
|
package nechotron
|
|
|
|
|
2023-01-24 00:37:08 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
2023-01-22 23:54:54 +03:00
|
|
|
|
|
|
|
type Command struct {
|
|
|
|
Body string
|
|
|
|
IsAdminOnly bool
|
2023-01-24 00:37:08 +03:00
|
|
|
Description string
|
2023-01-22 23:54:54 +03:00
|
|
|
}
|
|
|
|
|
2023-01-24 00:37:08 +03:00
|
|
|
func NewCommand(body string, desc string, isAdminOnly bool) *Command {
|
2023-01-22 23:54:54 +03:00
|
|
|
return &Command{
|
|
|
|
Body: body,
|
|
|
|
IsAdminOnly: isAdminOnly,
|
2023-01-24 00:37:08 +03:00
|
|
|
Description: desc,
|
2023-01-22 23:54:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-01-22 23:54:54 +03:00
|
|
|
// func HandleCommand(command *Command, handler cmdFunc) (bool, error)
|