Middleware
This commit is contained in:
17
command.go
17
command.go
@ -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)
|
||||
|
Reference in New Issue
Block a user