package nechotron import ( "errors" "github.com/NicoNex/echotron/v3" ) type StateData map[string]interface{} type Runnable interface { Call(*Update) error } type State struct { Fn stateFn } func (s *State) Call(u *Update) error { return s.Fn(u) } type stateFn func(*Update) error func (d StateData) Set(name string, data interface{}) { d[name] = data } func (d StateData) Get(name string) (interface{}, error) { data, ok := d[name] if !ok { return nil, errors.New("can't get data from statedata") } return data, nil } func (d StateData) Has(name string) bool { _, ok := d[name] return ok } func (d StateData) Clear() { for k := range d { delete(d, k) } } var EchoState = State{ Fn: EchoFunc, } func EchoFunc(u *Update) error { u.AnswerText(u.Text(), &echotron.MessageOptions{}) return nil }