@@ -311,6 +311,78 @@ func (s *RegexScriptService) substituteMacros(text string, userName string, char
|
||||
return result
|
||||
}
|
||||
|
||||
// ExtractSetVars 从文本中提取 {{setvar::key::value}} 并返回变量映射和清理后的文本
|
||||
func (s *RegexScriptService) ExtractSetVars(text string) (map[string]string, string) {
|
||||
vars := make(map[string]string)
|
||||
|
||||
// 匹配 {{setvar::key::value}}
|
||||
re := regexp.MustCompile(`\{\{setvar::([^:]+)::([^}]*)\}\}`)
|
||||
matches := re.FindAllStringSubmatch(text, -1)
|
||||
|
||||
for _, match := range matches {
|
||||
if len(match) == 3 {
|
||||
key := strings.TrimSpace(match[1])
|
||||
value := match[2]
|
||||
vars[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
// 从文本中移除所有 {{setvar::}} 标记
|
||||
cleanText := re.ReplaceAllString(text, "")
|
||||
|
||||
return vars, cleanText
|
||||
}
|
||||
|
||||
// SubstituteGetVars 替换文本中的 {{getvar::key}} 为实际变量值
|
||||
func (s *RegexScriptService) SubstituteGetVars(text string, variables map[string]string) string {
|
||||
result := text
|
||||
|
||||
// 匹配 {{getvar::key}}
|
||||
re := regexp.MustCompile(`\{\{getvar::([^}]+)\}\}`)
|
||||
result = re.ReplaceAllStringFunc(result, func(match string) string {
|
||||
matches := re.FindStringSubmatch(match)
|
||||
if len(matches) == 2 {
|
||||
key := strings.TrimSpace(matches[1])
|
||||
if value, ok := variables[key]; ok {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return "" // 如果变量不存在,返回空字符串
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// ExtractStatusBlock 提取 <Status_block> 中的 YAML 数据
|
||||
func (s *RegexScriptService) ExtractStatusBlock(text string) (string, string) {
|
||||
// 匹配 <Status_block>...</Status_block>
|
||||
re := regexp.MustCompile(`(?s)<Status_block>\s*(.*?)\s*</Status_block>`)
|
||||
matches := re.FindStringSubmatch(text)
|
||||
|
||||
if len(matches) == 2 {
|
||||
statusBlock := strings.TrimSpace(matches[1])
|
||||
cleanText := re.ReplaceAllString(text, "")
|
||||
return statusBlock, cleanText
|
||||
}
|
||||
|
||||
return "", text
|
||||
}
|
||||
|
||||
// ExtractMaintext 提取 <maintext> 中的内容
|
||||
func (s *RegexScriptService) ExtractMaintext(text string) (string, string) {
|
||||
// 匹配 <maintext>...</maintext>
|
||||
re := regexp.MustCompile(`(?s)<maintext>\s*(.*?)\s*</maintext>`)
|
||||
matches := re.FindStringSubmatch(text)
|
||||
|
||||
if len(matches) == 2 {
|
||||
maintext := strings.TrimSpace(matches[1])
|
||||
cleanText := re.ReplaceAllString(text, "")
|
||||
return maintext, cleanText
|
||||
}
|
||||
|
||||
return "", text
|
||||
}
|
||||
|
||||
// GetScriptsForPlacement 获取指定阶段的脚本
|
||||
func (s *RegexScriptService) GetScriptsForPlacement(userID uint, placement int, charID *uint, presetID *uint) ([]app.RegexScript, error) {
|
||||
var scripts []app.RegexScript
|
||||
|
||||
Reference in New Issue
Block a user