refactor(db): remove global_configs table and checks

This commit is contained in:
2025-12-17 19:11:12 +08:00
parent 42d49d661f
commit 76e7276b57
4 changed files with 1 additions and 46 deletions

View File

@@ -1,9 +1,6 @@
package cmds package cmds
import ( import (
"slices"
"github.com/awfufu/go-hurobot/internal/db"
"github.com/awfufu/qbot" "github.com/awfufu/qbot"
) )
@@ -31,10 +28,6 @@ func (cmd *EssenceCommand) Self() *cmdBase {
} }
func (cmd *EssenceCommand) Exec(b *qbot.Bot, msg *qbot.Message) { 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 { if msg.ReplyID == 0 {
b.SendGroupMsg(msg.GroupID, cmd.HelpMsg) b.SendGroupMsg(msg.GroupID, cmd.HelpMsg)
return return

View File

@@ -2,12 +2,10 @@ package cmds
import ( import (
"fmt" "fmt"
"slices"
"strconv" "strconv"
"strings" "strings"
"github.com/awfufu/go-hurobot/internal/config" "github.com/awfufu/go-hurobot/internal/config"
"github.com/awfufu/go-hurobot/internal/db"
"github.com/awfufu/qbot" "github.com/awfufu/qbot"
) )
@@ -39,10 +37,6 @@ func (cmd *GroupCommand) Self() *cmdBase {
} }
func (cmd *GroupCommand) Exec(b *qbot.Bot, msg *qbot.Message) { 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 { getText := func(i int) string {
if i < len(msg.Array) { if i < len(msg.Array) {
if txt := msg.Array[i].GetTextItem(); txt != nil { if txt := msg.Array[i].GetTextItem(); txt != nil {

View File

@@ -1,11 +1,9 @@
package cmds package cmds
import ( import (
"slices"
"strconv" "strconv"
"strings" "strings"
"github.com/awfufu/go-hurobot/internal/db"
"github.com/awfufu/qbot" "github.com/awfufu/qbot"
) )
@@ -36,10 +34,6 @@ func (cmd *SpecialtitleCommand) Self() *cmdBase {
} }
func (cmd *SpecialtitleCommand) Exec(b *qbot.Bot, msg *qbot.Message) { 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 targetUserID uint64
var title string var title string

View File

@@ -111,32 +111,6 @@ func JoinIDList(ids []uint64) string {
return strings.Join(strs, ",") 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() { func InitDB() {
var err error var err error
// Ensure directory exists // Ensure directory exists
@@ -149,7 +123,7 @@ func InitDB() {
log.Fatalln(err) log.Fatalln(err)
} }
PsqlConnected = true PsqlConnected = true
PsqlDB.AutoMigrate(&dbUsers{}, &dbMessages{}, &DbPermissions{}, &GlobalConfig{}) PsqlDB.AutoMigrate(&dbUsers{}, &dbMessages{}, &DbPermissions{})
} }
func SaveDatabase(msg *qbot.Message) error { func SaveDatabase(msg *qbot.Message) error {