Added the Go function for the Command structure.
This commit is contained in:
parent
7d149558f9
commit
908d235cad
3 changed files with 31 additions and 15 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"fmt"
|
||||
|
||||
"github.com/mojosa-software/got/tg"
|
||||
)
|
||||
|
@ -116,7 +117,13 @@ WithInitFunc(func(c *tg.Context) {
|
|||
tg.NewKeyboard().Row(
|
||||
tg.NewButton("GoT Github page").
|
||||
WithUrl("https://github.com/mojosa-software/got"),
|
||||
).Inline().Widget("The bot started!"),
|
||||
).Inline().Widget(
|
||||
fmt.Sprint(
|
||||
"The testing bot started!\n",
|
||||
"You can see the basics of usage in the ",
|
||||
"cmd/test/main.go file!",
|
||||
),
|
||||
),
|
||||
).WithReply(
|
||||
navKeyboard.Widget("Choose what you are interested in"),
|
||||
),
|
||||
|
@ -128,24 +135,28 @@ WithInitFunc(func(c *tg.Context) {
|
|||
tg.NewButton("Lower case").Go("lower-case"),
|
||||
).Row(
|
||||
backButton,
|
||||
).Reply().Widget(
|
||||
).Reply().WithOneTime(true).Widget(
|
||||
"Choose the function to mutate string",
|
||||
),
|
||||
),
|
||||
tg.NewNode(
|
||||
"upper-case", tg.NewPage().WithReply(
|
||||
backKeyboard.Reply().Widget(
|
||||
"Type a string and the bot will convert it to upper case",
|
||||
),
|
||||
backKeyboard.Reply().
|
||||
WithOneTime(true).
|
||||
Widget(
|
||||
"Type a string and the bot will convert it to upper case",
|
||||
),
|
||||
).WithSub(
|
||||
NewMutateMessageWidget(strings.ToUpper),
|
||||
),
|
||||
),
|
||||
tg.NewNode(
|
||||
"lower-case", tg.NewPage().WithReply(
|
||||
backKeyboard.Reply().Widget(
|
||||
"Type a string and the bot will convert it to lower case",
|
||||
),
|
||||
backKeyboard.Reply().
|
||||
WithOneTime(true).
|
||||
Widget(
|
||||
"Type a string and the bot will convert it to lower case",
|
||||
),
|
||||
).WithSub(
|
||||
NewMutateMessageWidget(strings.ToLower),
|
||||
),
|
||||
|
@ -180,10 +191,9 @@ WithInitFunc(func(c *tg.Context) {
|
|||
),
|
||||
)).WithCommands(
|
||||
tg.NewCommand("start").
|
||||
Desc("start or restart the bot or move to the start screen").
|
||||
ActionFunc(func(c *tg.Context){
|
||||
c.Go("/")
|
||||
}),
|
||||
Desc(
|
||||
"start or restart the bot or move to the start screen",
|
||||
).Go("/"),
|
||||
tg.NewCommand("hello").
|
||||
Desc("sends the 'Hello, World!' message back").
|
||||
ActionFunc(func(c *tg.Context) {
|
||||
|
|
|
@ -56,6 +56,13 @@ func (c *Command) Desc(desc string) *Command {
|
|||
return c
|
||||
}
|
||||
|
||||
func (c *Command) Go(pth Path, args ...any) *Command {
|
||||
return c.WithAction(ScreenGo{
|
||||
Path: pth,
|
||||
Args: args,
|
||||
})
|
||||
}
|
||||
|
||||
type GroupCommand struct {
|
||||
Name CommandName
|
||||
Description string
|
||||
|
@ -78,6 +85,7 @@ func (cmd *GroupCommand) ActionFunc(fn GroupActionFunc) *GroupCommand {
|
|||
return cmd.WithAction(fn)
|
||||
}
|
||||
|
||||
|
||||
func (cmd *GroupCommand) Desc(desc string) *GroupCommand {
|
||||
cmd.Description = desc
|
||||
return cmd
|
||||
|
@ -142,7 +150,7 @@ func (w *CommandWidget) WithUsageFunc(fn ActionFunc) *CommandWidget {
|
|||
return w.WithUsage(fn)
|
||||
}
|
||||
|
||||
func (widget *Command) Filter(
|
||||
func (widget *CommandWidget) Filter(
|
||||
u *Update,
|
||||
msgs ...*Message,
|
||||
) bool {
|
||||
|
|
|
@ -154,8 +154,6 @@ func (c *Context) Go(pth Path, args ...any) error {
|
|||
pth = (c.Path() + "/" + pth).Clean()
|
||||
}
|
||||
|
||||
c.Sendf("path: %q\nmap: %v", pth, c.Bot.behaviour.Screens)
|
||||
|
||||
if !c.PathExist(pth) {
|
||||
return ScreenNotExistErr
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue