Neur0toxine
77eaceb152
All checks were successful
continuous-integration/drone/push Build is passing
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package wizard
|
|
|
|
import (
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/fsm"
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/iface"
|
|
"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
|
|
}
|