nechotron/nechotron.go

47 lines
905 B
Go

package nechotron
import (
"log"
echo "github.com/NicoNex/echotron/v3"
)
type Nechotron struct {
Token string
DefaultState Runnable
ApiServer string
}
func NewTron(token string, defaultState *State) *Nechotron {
state := defaultState
if state == nil {
state = &EchoState
}
return &Nechotron{
Token: token,
DefaultState: state,
}
}
func (n *Nechotron) newBot(chatID int64) echo.Bot {
a := echo.NewCustomAPI(n.Token, n.ApiServer)
// a := echo.NewAPI(n.Token)
me, _ := a.GetMe()
// log.Println("New bot active: ", chatID, me.Result)
b := &bot{
chatID: chatID,
me: me.Result,
API: a,
state: n.DefaultState,
data: make(StateData),
}
b.state = n.DefaultState
return b
}
func (n *Nechotron) DispatchPoll() error {
dispatcher := echo.NewDispatcher(n.Token, n.newBot)
log.Println("Nechotron poll dispatcher started")
return dispatcher.Poll()
}