From 3a06ae5f0ec41195cde0e3376539393120a86278 Mon Sep 17 00:00:00 2001 From: nefrace Date: Fri, 20 Jan 2023 01:44:35 +0300 Subject: [PATCH] Added state interface for customizing --- bot.go | 2 +- state.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bot.go b/bot.go index 2dab810..73619d0 100644 --- a/bot.go +++ b/bot.go @@ -15,7 +15,7 @@ type bot struct { echo.API data StateData lock sync.Mutex - state *State + state Runnable } func (b *bot) Update(u *echo.Update) { diff --git a/state.go b/state.go index d1398f5..a4d1133 100644 --- a/state.go +++ b/state.go @@ -9,18 +9,18 @@ import ( type StateData map[string]interface{} type Runnable interface { - Call(*Update) (*State, error) + Call(*Update) (Runnable, error) } type State struct { fn stateFn } -func (s *State) Call(u *Update) (*State, error) { +func (s *State) Call(u *Update) (Runnable, error) { return s.fn(u) } -type stateFn func(*Update) (*State, error) +type stateFn func(*Update) (Runnable, error) func (d StateData) Set(name string, data interface{}) { d[name] = data @@ -49,7 +49,7 @@ var EchoState = State{ fn: EchoFunc, } -func EchoFunc(u *Update) (*State, error) { +func EchoFunc(u *Update) (Runnable, error) { u.AnswerText(u.Text(), &echotron.MessageOptions{}) return nil, nil }