package fsmwizard import ( "gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/db/model" "gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/iface" "gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/util" "gitea.neur0tx.site/Neur0toxine/vegapokerbot/pkg/fsm" "github.com/mymmrac/telego" tu "github.com/mymmrac/telego/telegoutil" ) const KeyboardChooserStateID fsm.StateID = "keyboard_chooser" type KeyboardChooserState struct { State } func NewKeyboardChooserState(app iface.App) fsm.IState[Wizard] { return &KeyboardChooserState{newBase(app)} } func (s *KeyboardChooserState) Enter(pl *Wizard, _ fsm.MachineControls[Wizard]) error { _, err := s.App.TG().SendMessage(&telego.SendMessageParams{ ChatID: tu.ID(pl.User.ChatID), Text: s.Localizer().Template("choose_keyboard", map[string]interface{}{"Name": pl.TGChat.Title}), ParseMode: telego.ModeMarkdown, ReplyMarkup: &telego.InlineKeyboardMarkup{ InlineKeyboard: [][]telego.InlineKeyboardButton{ { { Text: s.Localizer().Message("standard_vote_keyboard"), CallbackData: util.NewKeyboardChooserPayload( pl.User.TelegramID, pl.TGChat.ID, uint8(model.StandardKeyboard)).String(), }, }, { { Text: s.Localizer().Message("sp_vote_keyboard"), CallbackData: util.NewKeyboardChooserPayload( pl.User.TelegramID, pl.TGChat.ID, uint8(model.StoryPointsKeyboard)).String(), }, }, }, }, }) s.LogError(err) return err } func (s *KeyboardChooserState) Handle(pl *Wizard, mc fsm.MachineControls[Wizard]) { cr := s.App.DB().ForChat() result := pl.KeyClick.KeyboardChoice() if pl.KeyClick.User != pl.User.TelegramID { return } chat, err := cr.ByTelegramID(pl.KeyClick.Chat) if err != nil { s.LogError(err) return } if chat == nil || chat.ID == 0 { return } chat.KeyboardType = model.KeyboardType(result.Type) if err := cr.Save(chat); err != nil { s.LogError(err) return } kbTypeName := "standard_vote_keyboard" if model.KeyboardType(result.Type) == model.StoryPointsKeyboard { kbTypeName = "sp_vote_keyboard" } loc := s.Localizer(pl.User.Language) _, err = s.App.TG().EditMessageText(&telego.EditMessageTextParams{ ChatID: tu.ID(pl.User.ChatID), MessageID: pl.Data.CallbackQuery.Message.GetMessageID(), Text: loc.Template("chosen_keyboard", map[string]interface{}{"Name": loc.Message(kbTypeName)}), }) s.LogError(err) if !s.Payload.IsMaster { mc.Reset() return } s.Move(mc, ConfigureRedmineQueryStateID, pl) } func (s *KeyboardChooserState) ID() fsm.StateID { return KeyboardChooserStateID }