Middleware

This commit is contained in:
2023-01-24 00:37:08 +03:00
parent b074189d31
commit 599584ea58
6 changed files with 49 additions and 19 deletions

View File

@ -1,16 +1,21 @@
package nechotron
import "strings"
import (
"fmt"
"strings"
)
type Command struct {
Body string
IsAdminOnly bool
Description string
}
func NewCommand(body string, isAdminOnly bool) *Command {
func NewCommand(body string, desc string, isAdminOnly bool) *Command {
return &Command{
Body: body,
IsAdminOnly: isAdminOnly,
Description: desc,
}
}
func (c *Command) String() string {
@ -21,4 +26,12 @@ func (c *Command) Param(text string) string {
return strings.TrimPrefix(text, "/"+c.Body+" ")
}
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)