2024-05-13 19:21:34 +03:00
|
|
|
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 {
|
2024-05-13 19:46:55 +03:00
|
|
|
s.Move(mc, WaitingForMemberWebhookStateID, pl)
|
2024-05-13 19:21:34 +03:00
|
|
|
}
|
|
|
|
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))
|
|
|
|
}
|
2024-05-13 19:46:55 +03:00
|
|
|
s.Move(mc, WaitingForMemberWebhookStateID, pl)
|
2024-05-13 19:21:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoveChatMemberState) ID() fsm.StateID {
|
|
|
|
return RemoveChatMemberStateID
|
|
|
|
}
|