/
db.go
94 lines (78 loc) · 1.66 KB
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package utils
import (
"log"
"time"
tele "gopkg.in/telebot.v3"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
type Get struct {
Name string `gorm:"primaryKey"`
Title string
Type string
Data string
Caption string
Creator int64
}
type AntiSpam struct {
Text string `gorm:"primaryKey"`
Type string
}
type PidorStats struct {
Date time.Time `gorm:"primaryKey"`
UserID int64
}
type PidorList tele.User
type Duelist struct {
UserID int64 `gorm:"primaryKey"`
Deaths int
Kills int
}
type Warn struct {
UserID int64 `gorm:"primaryKey"`
Amount int
LastWarn time.Time
}
type Nope struct {
Text string `gorm:"primaryKey"`
}
type Bets struct {
UserID int64 `gorm:"primaryKey"`
Text string `gorm:"primaryKey"`
Timestamp int64 `gorm:"primaryKey"`
}
type StatsWords struct {
ID int64 `gorm:"primaryKey;autoIncrement"`
Word string
ShortWord string
}
type Stats struct {
ContextID int64 `gorm:"primaryKey"`
StatType int64 `gorm:"primaryKey"`
Count int64
DayTimestamp int64 `gorm:"primaryKey"`
LastUpdate int64 `gorm:"default:1685221200"`
}
type Bless struct {
Text string `gorm:"primaryKey"`
}
func DataBaseInit(file string) gorm.DB {
database, err := gorm.Open(
sqlite.Open(file),
&gorm.Config{
Logger: logger.Default.LogMode(logger.Warn),
},
)
if err != nil {
log.Fatal(err)
}
//Create tables, if they not exists in DB
err = database.AutoMigrate(tele.User{}, Get{}, Warn{}, PidorStats{}, PidorList{}, Duelist{}, Bless{}, Nope{}, Stats{}, StatsWords{}, Bets{})
if err != nil {
log.Println(err)
}
database.Exec("VACUUM;")
return *database
}
var DB = DataBaseInit("bot.db")