vegapokerbot/internal/handler/fsmwizard/waiting_for_member_webhook_state.go
Neur0toxine 1a28ab584a
Some checks are pending
continuous-integration/drone/push Build is running
move fsm wizard to its own package, little refactor
2024-05-13 19:21:34 +03:00

41 lines
1.3 KiB
Go

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) Handle(pl *Wizard, mc fsm.MachineControls[*Wizard]) {
cm := pl.Data.MyChatMember
if !cm.OldChatMember.MemberIsMember() && cm.OldChatMember.MemberUser().ID == s.App.TGProfile().ID &&
cm.NewChatMember.MemberIsMember() && cm.NewChatMember.MemberUser().ID == s.App.TGProfile().ID {
s.Move(mc, AddChatMemberStateID, pl)
return
}
if cm.OldChatMember.MemberIsMember() && cm.OldChatMember.MemberUser().ID == s.App.TGProfile().ID &&
!cm.NewChatMember.MemberIsMember() && cm.NewChatMember.MemberUser().ID == s.App.TGProfile().ID {
s.Move(mc, RemoveChatMemberStateID, pl)
return
}
s.LogError(s.App.TG().LeaveChat(&telego.LeaveChatParams{
ChatID: tu.ID(pl.Data.MyChatMember.Chat.ID),
}))
}
func (s *WaitingForMemberWebhookState) ID() fsm.StateID {
return WaitingForMemberWebhookStateID
}