2023-08-10 15:49:25 +03:00
|
|
|
package tx
|
2023-07-09 01:28:59 +03:00
|
|
|
|
2023-08-12 15:54:05 +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 {
|
2023-08-12 15:54:05 +03:00
|
|
|
Act(*Arg)
|
2023-07-09 01:28:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Customized action for the bot.
|
2023-08-12 15:54:05 +03:00
|
|
|
type ActionFunc func(*Arg)
|
2023-07-09 01:28:59 +03:00
|
|
|
|
|
|
|
// The type implements changing screen to the underlying ScreenId
|
|
|
|
type ScreenChange ScreenId
|
|
|
|
|
2023-08-12 15:54:05 +03:00
|
|
|
func (sc ScreenChange) Act(c *Arg) {
|
2023-08-10 15:49:25 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-08-12 15:54:05 +03:00
|
|
|
func (af ActionFunc) Act(c *Arg) {
|
2023-08-10 15:49:25 +03:00
|
|
|
af(c)
|
2023-07-09 01:28:59 +03:00
|
|
|
}
|