feat: support kick

This commit is contained in:
Vaala Cat
2023-06-19 19:21:26 +08:00
parent e516a51ebe
commit f0c2083bd7
16 changed files with 447 additions and 87 deletions

24
utils/database/db.go Normal file
View File

@@ -0,0 +1,24 @@
package database
import (
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
)
func init() {
godotenv.Load()
initSqlite()
}
func GetDB() *gorm.DB {
return GetSqlite()
}
func CloseDB(db *gorm.DB) {
tdb, err := db.DB()
if err != nil {
logrus.WithError(err).Errorf("Close DB error")
}
tdb.Close()
}

31
utils/database/sqlite.go Normal file
View File

@@ -0,0 +1,31 @@
package database
import (
"tg-mc/conf"
"github.com/glebarez/sqlite"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
)
func initSqlite() {
var err error
godotenv.Load()
dbPath := conf.GetBotSettings().DBPath
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
if err != nil {
logrus.Panic(err, "Initializing DB Error")
}
CloseDB(db)
}
func GetSqlite() *gorm.DB {
dbPath := conf.GetBotSettings().DBPath
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
if err != nil {
return nil
}
return db
}