This commit is contained in:
SmileRex
2025-01-05 23:43:46 +03:00
commit b18fd6d415
8 changed files with 1077 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package controllers
import (
"bot/src/models"
"math/rand"
"time"
"github.com/glebarez/sqlite"
"github.com/robfig/cron"
"gorm.io/gorm"
)
type DataController struct {
DB *gorm.DB
}
func NewDB() *DataController {
db, err := gorm.Open(sqlite.Open("users.db"), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
db.AutoMigrate(models.User{})
return &DataController{DB: db}
}
func RandRange() int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(21) - 5
}
func (d *DataController) ClearAllBlocked() {
d.DB.Model(&models.User{}).Where("is_blocked = ?", true).Update("is_blocked", false)
}
func (d *DataController) CronRun() {
c := cron.New()
c.AddFunc("0 20 * * *", func() {
d.ClearAllBlocked()
})
c.Start()
}