vegapokerbot/internal/handler/wizard/base.go

49 lines
979 B
Go
Raw Normal View History

2024-05-13 16:57:55 +03:00
package wizard
import (
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/fsm"
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/iface"
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/locale"
"github.com/mymmrac/telego"
"strings"
)
type Wizard struct {
UserID int64
ChatID int64
Data telego.Update
}
type State struct {
fsm.State[Wizard]
App iface.App
}
func newBase(app iface.App) State {
return State{App: app}
}
func (s State) Localizer(lang string) locale.Localizer {
lang = strings.ToLower(lang)
if len(lang) > 2 {
lang = lang[:2]
}
switch lang {
case "en", "ru":
return s.App.Localizer(lang)
default:
return s.App.Localizer("en")
}
}
func (s State) LogError(err error) {
if err == nil {
return
}
if s.App.Conf().Debug {
s.App.Log().Errorf("handler error: %s, payload: %#v", err, s.Payload)
return
}
s.App.Log().Errorf("handler error: %s, user id: %d, chat id: %d", err, s.Payload.UserID, s.Payload.ChatID)
}