vegapokerbot/internal/handler/wizard/waiting_for_member_webhook_state.go

41 lines
1.3 KiB
Go
Raw Normal View History

2024-05-13 17:18:22 +03:00
package wizard
import (
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/iface"
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/pkg/fsm"
2024-05-13 17:18:22 +03:00
"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 {
_ = mc.Move(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 {
_ = mc.Move(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
}