57 lines
1.6 KiB
Go
57 lines
1.6 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 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]) {
|
||
|
if s.Payload.Chat == nil {
|
||
|
chat, err := s.App.DB().ForChat().ByTelegramID(s.Payload.Data.MyChatMember.Chat.ID)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if chat != nil && chat.ID > 0 {
|
||
|
s.Payload.Chat = chat
|
||
|
}
|
||
|
}
|
||
|
if s.Payload.Chat != nil && s.Payload.Chat.ID > 0 {
|
||
|
user, _ := s.App.DB().ForUser().ByID(s.Payload.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(s.App.DB().ForChat().Delete(s.Payload.Chat))
|
||
|
}
|
||
|
s.Move(mc, WaitingForMemberWebhookStateID, pl)
|
||
|
}
|
||
|
|
||
|
func (s *RemoveChatMemberState) ID() fsm.StateID {
|
||
|
return RemoveChatMemberStateID
|
||
|
}
|