tg/beh.go

60 lines
1.2 KiB
Go
Raw Normal View History

2023-08-19 09:12:26 +03:00
package tg
2023-08-12 14:35:33 +03:00
// The type describes behaviour for the bot in personal chats.
type Behaviour struct {
Root Component
2024-03-29 14:30:48 +03:00
Init Action
//Screens ScreenMap
2023-08-12 14:35:33 +03:00
}
// Returns new empty behaviour.
func NewBehaviour() *Behaviour {
return &Behaviour{
}
}
// The Action will be called on session creation,
// not when starting or restarting the bot with the Start Action.
2024-03-29 14:30:48 +03:00
func (b *Behaviour) SetInit(a Action) *Behaviour {
b.Init = a
return b
}
/*func (b *Behaviour) SetScreens(screens ScreenMap) *Behaviour {
b.Screens = screens
return b
}
2024-03-29 14:30:48 +03:00
// Sets the root node of the Behaviour.
// Mostly used for commands and such stuff.
func (b *Behaviour) SetRootNode(node *RootNode) *Behaviour {
b.Screens = node.ScreenMap()
return b
}
*/
// The function sets as the standard root widget CommandWidget
// and its commands..
2024-03-29 14:30:48 +03:00
func (b *Behaviour) SetRootWidget(root Component) *Behaviour {
b.Root = root
2023-08-12 14:35:33 +03:00
return b
}
/*
// Check whether the screen exists in the behaviour.
func (beh *Behaviour) PathExist(pth Path) bool {
_, ok := beh.Screens[pth]
return ok
}
// Returns the screen by it's ID.
func (beh *Behaviour) GetScreen(pth Path) *Screen {
if !beh.PathExist(pth) {
panic(ScreenNotExistErr)
}
screen := beh.Screens[pth]
return screen
}
*/