2023-07-09 01:28:59 +03:00
|
|
|
package behx
|
|
|
|
|
|
|
|
// Implementing the intereface lets you
|
|
|
|
// provide behaviour for the buttons etc.
|
|
|
|
type Action interface {
|
2023-07-12 00:33:51 +03:00
|
|
|
Act(*Context)
|
2023-07-09 01:28:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Customized action for the bot.
|
2023-07-12 00:33:51 +03:00
|
|
|
type CustomAction func(*Context)
|
2023-07-09 01:28:59 +03:00
|
|
|
|
|
|
|
// The type implements changing screen to the underlying ScreenId
|
|
|
|
type ScreenChange ScreenId
|
|
|
|
|
|
|
|
// Returns new ScreenChange.
|
|
|
|
func NewScreenChange(screen string) ScreenChange {
|
|
|
|
return ScreenChange(screen)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns new CustomAction.
|
2023-07-12 00:33:51 +03:00
|
|
|
func NewCustomAction(fn func(*Context)) CustomAction {
|
2023-07-09 01:28:59 +03:00
|
|
|
return CustomAction(fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sc ScreenChange) Act(c *Context) {
|
|
|
|
c.ChangeScreen(ScreenId(sc))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ca CustomAction) Act(c *Context) {
|
2023-07-12 00:33:51 +03:00
|
|
|
ca(c)
|
2023-07-09 01:28:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
// The type describes interface
|
|
|
|
// defining what should be done.
|
|
|
|
type Actioner interface {
|
|
|
|
Act(*bot)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simple way to define that the button should just change
|
|
|
|
// screen to the Id.
|
|
|
|
type ScreenChanger ScreenId
|
|
|
|
|
|
|
|
// Custom function to be executed on button press.
|
|
|
|
type ActionFunc func(*Bot)
|
|
|
|
|
|
|
|
func (a ActionFunc) Act(bot *Bot) {
|
|
|
|
a(bot)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sc ScreenChanger) Act(bot *Bot) {
|
|
|
|
bot.ChangeScreenTo(sc)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|