mirror of
https://github.com/awfufu/go-hurobot.git
synced 2026-03-01 05:29:43 +08:00
refactor(db): remove global_configs table and checks
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/awfufu/go-hurobot/internal/db"
|
||||
"github.com/awfufu/qbot"
|
||||
)
|
||||
|
||||
@@ -31,10 +28,6 @@ func (cmd *EssenceCommand) Self() *cmdBase {
|
||||
}
|
||||
|
||||
func (cmd *EssenceCommand) Exec(b *qbot.Bot, msg *qbot.Message) {
|
||||
if !slices.Contains(db.GetGlobalIDs("bot_owner_group_ids"), msg.GroupID) {
|
||||
return
|
||||
}
|
||||
|
||||
if msg.ReplyID == 0 {
|
||||
b.SendGroupMsg(msg.GroupID, cmd.HelpMsg)
|
||||
return
|
||||
|
||||
@@ -2,12 +2,10 @@ package cmds
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/awfufu/go-hurobot/internal/config"
|
||||
"github.com/awfufu/go-hurobot/internal/db"
|
||||
"github.com/awfufu/qbot"
|
||||
)
|
||||
|
||||
@@ -39,10 +37,6 @@ func (cmd *GroupCommand) Self() *cmdBase {
|
||||
}
|
||||
|
||||
func (cmd *GroupCommand) Exec(b *qbot.Bot, msg *qbot.Message) {
|
||||
if !slices.Contains(db.GetGlobalIDs("bot_owner_group_ids"), msg.GroupID) {
|
||||
return
|
||||
}
|
||||
|
||||
getText := func(i int) string {
|
||||
if i < len(msg.Array) {
|
||||
if txt := msg.Array[i].GetTextItem(); txt != nil {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/awfufu/go-hurobot/internal/db"
|
||||
"github.com/awfufu/qbot"
|
||||
)
|
||||
|
||||
@@ -36,10 +34,6 @@ func (cmd *SpecialtitleCommand) Self() *cmdBase {
|
||||
}
|
||||
|
||||
func (cmd *SpecialtitleCommand) Exec(b *qbot.Bot, msg *qbot.Message) {
|
||||
if !slices.Contains(db.GetGlobalIDs("bot_owner_group_ids"), msg.GroupID) {
|
||||
return
|
||||
}
|
||||
|
||||
var targetUserID uint64
|
||||
var title string
|
||||
|
||||
|
||||
@@ -111,32 +111,6 @@ func JoinIDList(ids []uint64) string {
|
||||
return strings.Join(strs, ",")
|
||||
}
|
||||
|
||||
type GlobalConfig struct {
|
||||
Key string `gorm:"primaryKey;column:key"`
|
||||
Value string `gorm:"column:value"` // CSV string
|
||||
}
|
||||
|
||||
func (GlobalConfig) TableName() string {
|
||||
return "global_configs"
|
||||
}
|
||||
|
||||
func GetGlobalIDs(key string) []uint64 {
|
||||
var cfg GlobalConfig
|
||||
if err := PsqlDB.Where("key = ?", key).First(&cfg).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return ParseIDList(cfg.Value)
|
||||
}
|
||||
|
||||
func SaveGlobalIDs(key string, ids []uint64) error {
|
||||
val := JoinIDList(ids)
|
||||
cfg := GlobalConfig{
|
||||
Key: key,
|
||||
Value: val,
|
||||
}
|
||||
return PsqlDB.Save(&cfg).Error
|
||||
}
|
||||
|
||||
func InitDB() {
|
||||
var err error
|
||||
// Ensure directory exists
|
||||
@@ -149,7 +123,7 @@ func InitDB() {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
PsqlConnected = true
|
||||
PsqlDB.AutoMigrate(&dbUsers{}, &dbMessages{}, &DbPermissions{}, &GlobalConfig{})
|
||||
PsqlDB.AutoMigrate(&dbUsers{}, &dbMessages{}, &DbPermissions{})
|
||||
}
|
||||
|
||||
func SaveDatabase(msg *qbot.Message) error {
|
||||
|
||||
Reference in New Issue
Block a user