diff --git a/tg/action.go b/tg/action.go index 829744d..498580b 100644 --- a/tg/action.go +++ b/tg/action.go @@ -1,33 +1,9 @@ package tg import ( - "reflect" + //"reflect" ) -// Jsonable Action. -type action struct { - Type string - Action Action -} - -func newAction(a Action) *action { - typ, ok := actionMapByReflect[reflect.TypeOf(a)] - if !ok { - panic(ActionNotDefinedErr) - } - - return &action{ - Type: typ, - Action: a, - } -} - -func (a *action) Act(c *Context) { - if a != nil && a.Action != nil { - a.Action.Act(c) - } -} - // The argument for handling in channenl behaviours. type ChannelContext struct { } diff --git a/tg/beh.go b/tg/beh.go index 027d5b2..067cce5 100644 --- a/tg/beh.go +++ b/tg/beh.go @@ -6,7 +6,7 @@ package tg // The type describes behaviour for the bot in personal chats. type Behaviour struct { Root Widget - Init *action + Init Action Screens ScreenMap } @@ -26,7 +26,7 @@ func (b *Behaviour) WithRoot(root Widget) *Behaviour { // The Action will be called on session creation, // not when starting or restarting the bot with the Start Action. func (b *Behaviour) WithInit(a Action) *Behaviour { - b.Init = newAction(a) + b.Init = a return b } diff --git a/tg/button.go b/tg/button.go index 943b45c..c1472af 100644 --- a/tg/button.go +++ b/tg/button.go @@ -10,7 +10,7 @@ type Button struct { Data string Url string SendLocation bool - Action *action + Action Action } type ButtonMap map[string]*Button @@ -44,7 +44,7 @@ func (btn *Button) WithUrl(url string) *Button { // Set the action when pressing the button. // By default is nil and does nothing. func (btn *Button) WithAction(a Action) *Button { - btn.Action = newAction(a) + btn.Action = a return btn } diff --git a/tg/command.go b/tg/command.go index 8596852..048e6b2 100644 --- a/tg/command.go +++ b/tg/command.go @@ -15,7 +15,7 @@ type CommandName string type Command struct { Name CommandName Description string - Action *action + Action Action Widget Widget } type CommandMap map[CommandName]*Command @@ -27,7 +27,7 @@ func NewCommand(name CommandName) *Command { } func (c *Command) WithAction(a Action) *Command { - c.Action = newAction(a) + c.Action = a return c } diff --git a/tg/json.go b/tg/json.go index e7dfa2c..ef37f09 100644 --- a/tg/json.go +++ b/tg/json.go @@ -1,11 +1,11 @@ package tg import ( - "encoding/json" - "reflect" + //"encoding/json" + //"reflect" ) -func (a *action) UnmarshalJSON(data []byte) error { +/*func (a *action) UnmarshalJSON(data []byte) error { var err error m := make(map[string]any) err = json.Unmarshal(data, &m) @@ -31,4 +31,4 @@ func (a *action) UnmarshalJSON(data []byte) error { a.Action = vr return nil -} +}*/