新增正则和扩展模块

This commit is contained in:
2026-02-11 23:44:09 +08:00
parent 2bca8e2788
commit 4e611d3a5e
47 changed files with 10058 additions and 49 deletions

View File

@@ -0,0 +1,65 @@
package app
import (
"git.echol.cn/loser/st/server/global"
"github.com/lib/pq"
"gorm.io/datatypes"
)
// AIRegexScript 正则表达式脚本
type AIRegexScript struct {
global.GVA_MODEL
UserID uint `json:"userId" gorm:"not null;index;comment:用户ID"`
User *AppUser `json:"user" gorm:"foreignKey:UserID"`
// 基础信息
ScriptName string `json:"scriptName" gorm:"type:varchar(500);not null;comment:脚本名称"`
Description string `json:"description" gorm:"type:text;comment:脚本描述"`
// 脚本内容
FindRegex string `json:"findRegex" gorm:"type:text;not null;comment:查找正则表达式"`
ReplaceString string `json:"replaceString" gorm:"type:text;comment:替换字符串"`
// 脚本配置
Enabled bool `json:"enabled" gorm:"default:true;comment:是否启用"`
IsGlobal bool `json:"isGlobal" gorm:"default:false;index;comment:是否全局脚本"`
TrimStrings bool `json:"trimStrings" gorm:"default:false;comment:是否去除首尾空格"`
OnlyFormat bool `json:"onlyFormat" gorm:"default:false;comment:仅格式化消息"`
RunOnEdit bool `json:"runOnEdit" gorm:"default:false;comment:编辑时运行"`
SubstituteRegex bool `json:"substituteRegex" gorm:"default:false;comment:替换正则"`
MinDepth *int `json:"minDepth" gorm:"comment:最小深度"`
MaxDepth *int `json:"maxDepth" gorm:"comment:最大深度"`
// 应用范围
Placement string `json:"placement" gorm:"type:varchar(50);comment:应用位置:user,ai,sys,slash"` // user, ai, sys, slash
AffectMinDepth *int `json:"affectMinDepth" gorm:"comment:影响最小深度"`
AffectMaxDepth *int `json:"affectMaxDepth" gorm:"comment:影响最大深度"`
// 关联数据
LinkedChars pq.StringArray `json:"linkedChars" gorm:"type:text[];comment:关联的角色ID列表"`
// 扩展数据(用于存储额外配置)
ScriptData datatypes.JSON `json:"scriptData" gorm:"type:jsonb;comment:脚本附加数据"`
// 统计信息
UsageCount int `json:"usageCount" gorm:"default:0;comment:使用次数"`
LastUsedAt *int64 `json:"lastUsedAt" gorm:"comment:最后使用时间戳"`
}
func (AIRegexScript) TableName() string {
return "ai_regex_scripts"
}
// AICharacterRegexScript 角色与正则脚本关联表
type AICharacterRegexScript struct {
global.GVA_MODEL
CharacterID uint `json:"characterId" gorm:"not null;index:idx_char_regex,unique;comment:角色ID"`
Character *AICharacter `json:"character" gorm:"foreignKey:CharacterID"`
RegexID uint `json:"regexId" gorm:"not null;index:idx_char_regex,unique;comment:正则脚本ID"`
Regex *AIRegexScript `json:"regex" gorm:"foreignKey:RegexID"`
Order int `json:"order" gorm:"default:0;comment:执行顺序"`
}
func (AICharacterRegexScript) TableName() string {
return "ai_character_regex_scripts"
}