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 RemoveChatMemberStateID fsm.StateID = "remove_chat_member" type RemoveChatMemberState struct { State } func NewRemoveChatMemberState(app iface.App) fsm.IState[Wizard] { return &RemoveChatMemberState{newBase(app)} } func (s *RemoveChatMemberState) Enter(pl *Wizard, mc fsm.MachineControls[*Wizard]) error { if pl.Data.MyChatMember == nil { s.Move(mc, WaitingForMemberWebhookStateID, pl) } return nil } func (s *RemoveChatMemberState) Handle(pl *Wizard, mc fsm.MachineControls[*Wizard]) { cr := s.App.DB().ForChat() chat, err := cr.ByTelegramID(pl.Data.MyChatMember.Chat.ID) if err != nil { s.LogError(err) return } if chat != nil && chat.ID > 0 { user, _ := s.App.DB().ForUser().ByID(chat.UserID) if user != nil && user.ID > 0 && user.ChatID > 0 { _, err := s.App.TG().SendMessage(&telego.SendMessageParams{ ChatID: tu.ID(user.ChatID), Text: s.Localizer(user.Language).Template( "bot_was_removed_from_group", map[string]interface{}{"Name": pl.Data.MyChatMember.Chat.Title}), ParseMode: telego.ModeMarkdown, }) s.LogError(err) } s.LogError(cr.Delete(chat)) } s.Move(mc, WaitingForMemberWebhookStateID, pl) } func (s *RemoveChatMemberState) ID() fsm.StateID { return RemoveChatMemberStateID }