2024-05-07 22:07:53 +03:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2024-05-09 17:42:42 +03:00
|
|
|
"encoding/json"
|
2024-05-09 20:48:59 +03:00
|
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/iface"
|
2024-05-09 23:26:21 +03:00
|
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/store"
|
2024-05-09 17:42:42 +03:00
|
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/util"
|
|
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/wizard"
|
2024-05-07 22:07:53 +03:00
|
|
|
"github.com/mymmrac/telego"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MessageHandler struct {
|
2024-05-09 20:48:59 +03:00
|
|
|
app iface.App
|
2024-05-07 22:07:53 +03:00
|
|
|
}
|
|
|
|
|
2024-05-09 20:48:59 +03:00
|
|
|
func NewMessageHandler(app iface.App) Handler {
|
2024-05-07 22:07:53 +03:00
|
|
|
return &MessageHandler{app: app}
|
|
|
|
}
|
|
|
|
|
2024-05-09 17:42:42 +03:00
|
|
|
func (h *MessageHandler) Handle(wh telego.Update) error {
|
2024-05-09 20:48:59 +03:00
|
|
|
if wh.Message.From != nil &&
|
|
|
|
wh.Message.Chat.Type == telego.ChatTypePrivate {
|
|
|
|
if util.MatchCommand("start", wh.Message) {
|
2024-05-09 17:42:42 +03:00
|
|
|
return wizard.NewRegister(h.app, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh)
|
|
|
|
}
|
2024-05-09 20:48:59 +03:00
|
|
|
if util.MatchCommand("help", wh.Message) {
|
|
|
|
return wizard.NewHelpCommand(h.app, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh)
|
|
|
|
}
|
2024-05-09 23:26:21 +03:00
|
|
|
|
|
|
|
setup, found := store.RedmineSetups.Get(wh.Message.Chat.ID)
|
|
|
|
if found {
|
|
|
|
return wizard.NewRedmineSetup(h.app, wh.Message.From.ID, wh.Message.Chat.ID, setup).Handle(wh)
|
|
|
|
}
|
|
|
|
|
2024-05-09 20:48:59 +03:00
|
|
|
return wizard.NewUnknownCommand(h.app, wh.Message.From.ID, wh.Message.Chat.ID).Handle(wh)
|
2024-05-09 17:42:42 +03:00
|
|
|
}
|
|
|
|
|
2024-05-09 20:48:59 +03:00
|
|
|
// 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))
|
|
|
|
|
2024-05-09 17:42:42 +03:00
|
|
|
return nil
|
2024-05-07 22:07:53 +03:00
|
|
|
}
|