2022-02-04 12:35:47 +03:00
|
|
|
package kicker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"kickerbot/db"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2022-11-09 00:45:08 +03:00
|
|
|
tb "github.com/NicoNex/echotron/v3"
|
2022-02-04 12:35:47 +03:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
)
|
|
|
|
|
2022-11-09 00:45:08 +03:00
|
|
|
type TaskBot struct {
|
|
|
|
Token string
|
|
|
|
tb.API
|
|
|
|
}
|
|
|
|
|
|
|
|
func TaskKickOldUsers(b *tb.API) {
|
2022-02-04 12:35:47 +03:00
|
|
|
d := db.GetDatabase()
|
2022-02-04 13:20:29 +03:00
|
|
|
log.Print("STARTING KICKING TASK")
|
2022-02-04 12:35:47 +03:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
now := time.Now().Unix()
|
2022-04-05 11:18:10 +03:00
|
|
|
old := now - 120
|
2022-02-04 12:35:47 +03:00
|
|
|
filter := bson.D{
|
2022-02-04 13:20:29 +03:00
|
|
|
primitive.E{Key: "date_joined", Value: bson.D{bson.E{Key: "$lt", Value: old}}},
|
2022-02-04 12:35:47 +03:00
|
|
|
}
|
|
|
|
users, err := d.GetUsers(ctx, filter)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error in deleting task: %v", err)
|
|
|
|
}
|
|
|
|
for _, user := range users {
|
2022-11-09 00:45:08 +03:00
|
|
|
b.BanChatMember(user.ChatId, user.Id, &tb.BanOptions{RevokeMessages: true})
|
|
|
|
b.DeleteMessage(user.ChatId, user.CaptchaMessage)
|
|
|
|
b.DeleteMessage(user.ChatId, user.JoinedMessage)
|
2022-02-04 12:56:31 +03:00
|
|
|
d.RemoveUser(ctx, user)
|
2022-02-04 12:35:47 +03:00
|
|
|
}
|
|
|
|
}
|