From 677f28182abe3f5301c1171f6083caa7e0914a48 Mon Sep 17 00:00:00 2001 From: nefrace Date: Fri, 20 Jan 2023 16:32:13 +0300 Subject: [PATCH] Custom API server --- nechotron.go | 6 ++++-- state.go | 6 +++--- update.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/nechotron.go b/nechotron.go index 92cee39..52c8ae6 100644 --- a/nechotron.go +++ b/nechotron.go @@ -8,7 +8,8 @@ import ( type Nechotron struct { Token string - DefaultState *State + DefaultState Runnable + ApiServer string } func NewTron(token string, defaultState *State) *Nechotron { @@ -23,7 +24,8 @@ func NewTron(token string, defaultState *State) *Nechotron { } func (n *Nechotron) newBot(chatID int64) echo.Bot { - a := echo.NewAPI(n.Token) + 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{ diff --git a/state.go b/state.go index a4d1133..6d0ecbc 100644 --- a/state.go +++ b/state.go @@ -13,11 +13,11 @@ type Runnable interface { } type State struct { - fn stateFn + Fn stateFn } func (s *State) Call(u *Update) (Runnable, error) { - return s.fn(u) + return s.Fn(u) } type stateFn func(*Update) (Runnable, error) @@ -46,7 +46,7 @@ func (d StateData) Clear() { } var EchoState = State{ - fn: EchoFunc, + Fn: EchoFunc, } func EchoFunc(u *Update) (Runnable, error) { diff --git a/update.go b/update.go index 2e1ab8b..b056a29 100644 --- a/update.go +++ b/update.go @@ -188,7 +188,7 @@ func (u *Update) LogError(text string, e error, send bool) { } else { text = "Произошла внутренняя ошибка" } - log.Printf("[%s] %s: %v", u.UpdateID.String(), text, e) + log.Printf("ERROR :: [%s] :: %s: %v", u.UpdateID.String(), text, e) if send { u.AnswerMarkdown(fmt.Sprintf("%s\nКод запроса: `%s`", text, u.UpdateID.String())) }