package app import ( "time" "gorm.io/datatypes" "gorm.io/gorm" ) // RegexScript 正则脚本模型(完全兼容 SillyTavern 格式) type RegexScript struct { ID uint `gorm:"primarykey" json:"id"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` UserID uint `gorm:"index;not null" json:"userId"` Name string `gorm:"type:varchar(100);not null" json:"name"` // 脚本名称 // 正则表达式 FindRegex string `gorm:"type:text;not null" json:"findRegex"` // 查找的正则表达式 ReplaceWith string `gorm:"type:text" json:"replaceWith"` // 替换的内容 TrimStrings datatypes.JSON `gorm:"type:jsonb" json:"trimStrings"` // 要修剪的字符串列表 []string // 执行阶段 // 0=输入(input), 1=输出(output), 2=世界书(world_info), 3=推理(display) Placement int `gorm:"default:1" json:"placement"` // 执行选项 Disabled bool `gorm:"default:false" json:"disabled"` // 是否禁用 MarkdownOnly bool `gorm:"default:false" json:"markdownOnly"` // 仅在 Markdown 模式下执行 RunOnEdit bool `gorm:"default:false" json:"runOnEdit"` // 编辑消息时执行 PromptOnly bool `gorm:"default:false" json:"promptOnly"` // 仅在 prompt 中执行 // 宏替换 SubstituteRegex bool `gorm:"default:true" json:"substituteRegex"` // 是否替换宏变量 {{user}}/{{char}} // 深度控制 MinDepth *int `gorm:"type:int" json:"minDepth"` // 最小深度(null 表示不限制) MaxDepth *int `gorm:"type:int" json:"maxDepth"` // 最大深度(null 表示不限制) // 作用域 // 0=全局(global), 1=角色(character), 2=预设(preset) Scope int `gorm:"default:0" json:"scope"` OwnerCharID *uint `gorm:"type:int" json:"ownerCharId"` // 角色ID(scope=1时有效) OwnerPresetID *uint `gorm:"type:int" json:"ownerPresetId"` // 预设ID(scope=2时有效) // 执行顺序 Order int `gorm:"default:100" json:"order"` // 执行顺序,数字越小越先执行 // 扩展字段 Extensions datatypes.JSON `gorm:"type:jsonb" json:"extensions"` } func (RegexScript) TableName() string { return "regex_scripts" }