tg/src/tx/action.go

47 lines
768 B
Go
Raw Normal View History

package tx
2023-07-09 01:28:59 +03:00
import (
apix "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
type Update = apix.Update
// The argument for handling.
type Arg struct {
// Current context.
*Context
// The update that made the action to be called.
U *Update
}
type A = Arg
type GroupArg struct {
GroupArg *GroupContext
U *Update
}
type GA = GroupArg
2023-07-09 01:28:59 +03:00
type Action interface {
Act(*Arg)
2023-07-09 01:28:59 +03:00
}
// Customized action for the bot.
type ActionFunc func(*Arg)
2023-07-09 01:28:59 +03:00
// The type implements changing screen to the underlying ScreenId
type ScreenChange ScreenId
func (sc ScreenChange) Act(c *Arg) {
if !c.B.ScreenExist(ScreenId(sc)) {
panic(ScreenNotExistErr)
}
2023-07-12 14:06:05 +03:00
err := c.ChangeScreen(ScreenId(sc))
if err != nil {
panic(err)
}
2023-07-09 01:28:59 +03:00
}
func (af ActionFunc) Act(c *Arg) {
af(c)
2023-07-09 01:28:59 +03:00
}