add Metadata field in BotContent table

This commit is contained in:
Akulij 2025-03-29 19:18:23 +08:00
parent 95e92dea3c
commit ce608abff1

View File

@ -45,6 +45,7 @@ type BotContent struct {
gorm.Model gorm.Model
Literal string Literal string
Content string Content string
Metadata string
} }
func GetDB() (*gorm.DB, error) { func GetDB() (*gorm.DB, error) {
@ -78,10 +79,20 @@ func (bc BotController) GetBotContent(Literal string) string {
return content return content
} }
func (bc BotController) SetBotContent(Literal string, Content string) { func (bc BotController) GetBotContentMetadata(Literal string) (string, error) {
c := BotContent{Literal: Literal, Content: Content} var c BotContent
bc.db.First(&c, "Literal", Literal)
if c == (BotContent{}) {
return "[]", errors.New("No metadata")
}
return c.Metadata, nil
}
func (bc BotController) SetBotContent(Literal string, Content string, Metadata string) {
c := BotContent{Literal: Literal, Content: Content, Metadata: Metadata}
bc.db.FirstOrCreate(&c, "Literal", Literal) bc.db.FirstOrCreate(&c, "Literal", Literal)
bc.db.Model(&c).Update("Content", Content) bc.db.Model(&c).Update("Content", Content)
bc.db.Model(&c).Update("Metadata", Metadata)
} }
func (bc BotController) GetUser(UserID int64) User { func (bc BotController) GetUser(UserID int64) User {