package kicker import ( "context" "fmt" "kickerbot/db" "log" "time" "git.nefrace.ru/nefrace/tongo" "github.com/NicoNex/echotron/v3" ) type TaskBot struct { Token string echotron.API } func TaskKickOldUsers(b *echotron.API) { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() now := time.Now() old := now.Add(-10 * time.Minute) store := tongo.NewStore[db.User](Client) users, err := store.GetMany(ctx, tongo.E("date_joined", tongo.D(tongo.E("$lt", old))), tongo.E("is_joined", false)) if err != nil { log.Printf("Error in deleting task: %v", err) } for _, user := range users { _, err := b.BanChatMember(user.ChatId, user.UserId, &echotron.BanOptions{RevokeMessages: true}) if err != nil { log.Println("User was not banned: ", err) continue } log.Printf("User %s was banned", user.FirstName) store.DeleteByID(ctx, user.Id) } } func TaskNotifyUsers(b *echotron.API) { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() store := tongo.NewStore[db.User](Client) chatStore := tongo.NewStore[db.Chat](Client) users, _ := store.GetMany(ctx, tongo.E("is_joined", false)) for _, user := range users { if time.Since(user.LastNotification) > 2*time.Minute { user.LastNotification = time.Now() text := fmt.Sprintf("*%s*, напоминаю, что тебе необходимо пройти капчу\\!", UserMentionDB(user)) store.ReplaceItem(ctx, *user, false) chat, err := chatStore.GetOne(ctx, tongo.E("chat_id", user.ChatId)) var topic int64 = 0 if err != nil { log.Printf("Can't get chat from user: %s", err) return } else { topic = chat.TopicId } res, err := b.SendMessage(text, user.ChatId, &echotron.MessageOptions{MessageThreadID: topic, ParseMode: echotron.MarkdownV2, ReplyToMessageID: user.CaptchaMessage}) if err != nil { log.Printf("Can't send notification to user: %s", err) } go waitAndDelete(b, res.Result, 2*time.Minute) } } }