beh.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package tg
  2. // The type describes behaviour for the bot in personal chats.
  3. type Behaviour struct {
  4. Root Component
  5. Init Action
  6. //Screens ScreenMap
  7. }
  8. // Returns new empty behaviour.
  9. func NewBehaviour() *Behaviour {
  10. return &Behaviour{
  11. }
  12. }
  13. // The Action will be called on session creation,
  14. // not when starting or restarting the bot with the Start Action.
  15. func (b *Behaviour) SetInit(a Action) *Behaviour {
  16. b.Init = a
  17. return b
  18. }
  19. /*func (b *Behaviour) SetScreens(screens ScreenMap) *Behaviour {
  20. b.Screens = screens
  21. return b
  22. }
  23. // Sets the root node of the Behaviour.
  24. // Mostly used for commands and such stuff.
  25. func (b *Behaviour) SetRootNode(node *RootNode) *Behaviour {
  26. b.Screens = node.ScreenMap()
  27. return b
  28. }
  29. */
  30. // The function sets as the standard root widget CommandWidget
  31. // and its commands..
  32. func (b *Behaviour) SetRootWidget(root Component) *Behaviour {
  33. b.Root = root
  34. return b
  35. }
  36. /*
  37. // Check whether the screen exists in the behaviour.
  38. func (beh *Behaviour) PathExist(pth Path) bool {
  39. _, ok := beh.Screens[pth]
  40. return ok
  41. }
  42. // Returns the screen by it's ID.
  43. func (beh *Behaviour) GetScreen(pth Path) *Screen {
  44. if !beh.PathExist(pth) {
  45. panic(ScreenNotExistErr)
  46. }
  47. screen := beh.Screens[pth]
  48. return screen
  49. }
  50. */