group_helper/telegram/routines/joinwritingchecker.go

38 lines
1003 B
Go
Raw Normal View History

package routines
import (
"git.dragon-labs.de/alphyron/group_helper/models"
"git.dragon-labs.de/alphyron/group_helper/obj"
"git.dragon-labs.de/alphyron/group_helper/telegram"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
)
type joinWritingCheckerRoutine struct {
verifyData *obj.VerifyData
}
func NewJoinWritingCheckerRoutine(verifyData *obj.VerifyData) telegram.Routine {
return joinWritingCheckerRoutine{
verifyData: verifyData,
}
}
func (j joinWritingCheckerRoutine) Update(botAPI *tgbotapi.BotAPI, update *tgbotapi.Update, group *models.Group) error {
if update.Message == nil { // ignore any non-Message Updates
return nil
}
if update.Message.Chat.IsPrivate() || update.Message.Chat.IsChannel() {
return nil
}
if j.verifyData.ExistCountdownForUserInGroup(update.Message.From.ID, group.GroupID) {
if group.ForbidWriting {
_, err := botAPI.DeleteMessage(tgbotapi.NewDeleteMessage(group.GroupID, update.Message.MessageID))
return err
}
}
return nil
}