Added state interface for customizing
This commit is contained in:
2
bot.go
2
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) {
|
||||
|
8
state.go
8
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user