39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/iface"
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/util"
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/wizard"
|
|
"github.com/mymmrac/telego"
|
|
)
|
|
|
|
type MessageHandler struct {
|
|
app iface.App
|
|
}
|
|
|
|
func NewMessageHandler(app iface.App) Handler {
|
|
return &MessageHandler{app: app}
|
|
}
|
|
|
|
func (h *MessageHandler) Handle(wh telego.Update) error {
|
|
if wh.Message.From != nil &&
|
|
wh.Message.Chat.Type == telego.ChatTypePrivate {
|
|
if util.MatchCommand("start", wh.Message) {
|
|
return wizard.NewRegister(h.app, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh)
|
|
}
|
|
if util.MatchCommand("help", wh.Message) {
|
|
return wizard.NewHelpCommand(h.app, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh)
|
|
}
|
|
return wizard.NewUnknownCommand(h.app, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh)
|
|
}
|
|
|
|
// TODO: Remove debug statement below.
|
|
h.app.Log().Debugf("New Message: %s", func(msg *telego.Message) string {
|
|
data, _ := json.Marshal(msg)
|
|
return string(data)
|
|
}(wh.Message))
|
|
|
|
return nil
|
|
}
|