2023-08-12 14:35:33 +03:00
|
|
|
package tx
|
|
|
|
|
|
|
|
import (
|
|
|
|
//"flag"
|
|
|
|
|
|
|
|
apix "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Message = apix.Message
|
|
|
|
type CommandName string
|
|
|
|
|
|
|
|
type Command struct {
|
|
|
|
Name CommandName
|
|
|
|
Description string
|
2023-08-16 17:25:56 +03:00
|
|
|
Action *action
|
2023-08-12 14:35:33 +03:00
|
|
|
}
|
2023-08-13 15:37:36 +03:00
|
|
|
type CommandMap map[CommandName]*Command
|
2023-08-12 14:35:33 +03:00
|
|
|
|
|
|
|
func NewCommand(name CommandName) *Command {
|
|
|
|
return &Command{
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Command) WithAction(a Action) *Command {
|
2023-08-16 17:25:56 +03:00
|
|
|
c.Action = newAction(a)
|
2023-08-12 14:35:33 +03:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Command) ActionFunc(af ActionFunc) *Command {
|
|
|
|
return c.WithAction(af)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Command) Desc(desc string) *Command {
|
|
|
|
c.Description = desc
|
|
|
|
return c
|
|
|
|
}
|
2023-08-13 15:37:36 +03:00
|
|
|
|
|
|
|
type GroupCommand struct {
|
|
|
|
Name CommandName
|
|
|
|
Description string
|
|
|
|
Action GroupAction
|
|
|
|
}
|
|
|
|
type GroupCommandMap map[CommandName]*GroupCommand
|
|
|
|
|
|
|
|
func NewGroupCommand(name CommandName) *GroupCommand {
|
|
|
|
return &GroupCommand{
|
|
|
|
Name: name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *GroupCommand) WithAction(a GroupAction) *GroupCommand {
|
|
|
|
cmd.Action = a
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *GroupCommand) ActionFunc(fn GroupActionFunc) *GroupCommand {
|
|
|
|
return cmd.WithAction(fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *GroupCommand) Desc(desc string) *GroupCommand {
|
|
|
|
cmd.Description = desc
|
|
|
|
return cmd
|
|
|
|
}
|