2023-08-19 09:12:26 +03:00
|
|
|
package tg
|
2023-08-10 15:49:25 +03:00
|
|
|
|
2023-08-12 14:35:33 +03:00
|
|
|
// The type describes behaviour for the bot in personal chats.
|
2023-08-10 15:49:25 +03:00
|
|
|
type Behaviour struct {
|
2023-09-27 14:09:49 +03:00
|
|
|
Root Component
|
2024-03-29 14:30:48 +03:00
|
|
|
Init Action
|
2024-07-21 16:02:47 +03:00
|
|
|
//Screens ScreenMap
|
2023-08-12 14:35:33 +03:00
|
|
|
}
|
|
|
|
|
2023-08-10 15:49:25 +03:00
|
|
|
// Returns new empty behaviour.
|
|
|
|
func NewBehaviour() *Behaviour {
|
|
|
|
return &Behaviour{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-16 17:25:56 +03:00
|
|
|
// 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 {
|
2023-09-21 20:32:24 +03:00
|
|
|
b.Init = a
|
2023-08-10 15:49:25 +03:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
/*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 {
|
2023-09-21 12:03:54 +03:00
|
|
|
b.Screens = node.ScreenMap()
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
*/
|
2023-09-11 15:58:45 +03:00
|
|
|
// 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 {
|
2023-09-27 14:09:49 +03:00
|
|
|
b.Root = root
|
2023-08-12 14:35:33 +03:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2024-07-21 16:02:47 +03:00
|
|
|
/*
|
2023-08-10 15:49:25 +03:00
|
|
|
// Check whether the screen exists in the behaviour.
|
2023-09-21 12:03:54 +03:00
|
|
|
func (beh *Behaviour) PathExist(pth Path) bool {
|
|
|
|
_, ok := beh.Screens[pth]
|
2023-08-10 15:49:25 +03:00
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the screen by it's ID.
|
2023-09-21 12:03:54 +03:00
|
|
|
func (beh *Behaviour) GetScreen(pth Path) *Screen {
|
|
|
|
if !beh.PathExist(pth) {
|
2023-08-10 15:49:25 +03:00
|
|
|
panic(ScreenNotExistErr)
|
|
|
|
}
|
|
|
|
|
2023-09-21 12:03:54 +03:00
|
|
|
screen := beh.Screens[pth]
|
2023-08-10 15:49:25 +03:00
|
|
|
return screen
|
|
|
|
}
|
2024-07-21 16:02:47 +03:00
|
|
|
*/
|