package fsmwizard import ( "gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/iface" "gitea.neur0tx.site/Neur0toxine/vegapokerbot/pkg/fsm" "github.com/mymmrac/telego" tu "github.com/mymmrac/telego/telegoutil" ) const WaitingForMemberWebhookStateID fsm.StateID = "waiting_for_member_webhook" type WaitingForMemberWebhookState struct { State } func NewWaitingForMemberWebhookState(app iface.App) fsm.IState[Wizard] { return &WaitingForMemberWebhookState{newBase(app)} } func (s *WaitingForMemberWebhookState) Enter(pl *Wizard, mc fsm.MachineControls[Wizard]) error { cm := pl.Data.MyChatMember if cm == nil { return nil } if !cm.OldChatMember.MemberIsMember() && cm.OldChatMember.MemberUser().ID == s.App.TGProfile().ID && cm.NewChatMember.MemberIsMember() && cm.NewChatMember.MemberUser().ID == s.App.TGProfile().ID { s.MoveForHandle(mc, AddChatMemberStateID, pl) return nil } if cm.OldChatMember.MemberIsMember() && cm.OldChatMember.MemberUser().ID == s.App.TGProfile().ID && !cm.NewChatMember.MemberIsMember() && cm.NewChatMember.MemberUser().ID == s.App.TGProfile().ID { s.MoveForHandle(mc, RemoveChatMemberStateID, pl) return nil } s.LogError(s.App.TG().LeaveChat(&telego.LeaveChatParams{ ChatID: tu.ID(pl.Data.MyChatMember.Chat.ID), })) return nil } func (s *WaitingForMemberWebhookState) Handle(pl *Wizard, mc fsm.MachineControls[Wizard]) { // By using this we can handle both Move from Register state and Move from waiting for webhook state. // The first one doesn't have data yet and it will be handled by Handle, the second one has data and will be // handled by Enter. _ = s.Enter(pl, mc) } func (s *WaitingForMemberWebhookState) ID() fsm.StateID { return WaitingForMemberWebhookStateID }