diff --git a/config/config.go b/config/config.go index 0d15edee..54bb8660 100644 --- a/config/config.go +++ b/config/config.go @@ -93,6 +93,7 @@ type Settings struct { LaunchReconectTimes int `yaml:"launch_reconnect_times"` UnlockPrefix string `yaml:"unlock_prefix"` WhiteBypass []int64 `yaml:"white_bypass"` + TransferUrl bool `yaml:"transfer_url"` } // LoadConfig 从文件中加载配置并初始化单例配置 @@ -1117,3 +1118,16 @@ func GetWhiteBypass() []int64 { } return nil // 返回nil,如果instance为nil } + +// 获取GetTransferUrl的值 +func GetTransferUrl() bool { + mu.Lock() + defer mu.Unlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to GetTransferUrl value.") + return false + } + return instance.Settings.TransferUrl +} + diff --git a/handlers/message_parser.go b/handlers/message_parser.go index 8df7d2c7..9f18ffa8 100644 --- a/handlers/message_parser.go +++ b/handlers/message_parser.go @@ -224,29 +224,32 @@ func transformMessageText(messageText string) string { } return m }) - // 判断服务器地址是否是IP地址 - serverAddress := config.GetServer_dir() - isIP := isIPAddress(serverAddress) - VisualIP := config.GetVisibleIP() - // 使用xurls来查找和替换所有的URL - messageText = xurls.Relaxed.ReplaceAllStringFunc(messageText, func(originalURL string) string { - // 当服务器地址是IP地址且GetVisibleIP为false时,替换URL为空 - if isIP && !VisualIP { - return "" - } + //是否处理url + if config.GetTransferUrl() { + // 判断服务器地址是否是IP地址 + serverAddress := config.GetServer_dir() + isIP := isIPAddress(serverAddress) + VisualIP := config.GetVisibleIP() + // 使用xurls来查找和替换所有的URL + messageText = xurls.Relaxed.ReplaceAllStringFunc(messageText, func(originalURL string) string { + // 当服务器地址是IP地址且GetVisibleIP为false时,替换URL为空 + if isIP && !VisualIP { + return "" + } - // 根据配置处理URL - if config.GetLotusValue() { - // 连接到另一个gensokyo - shortURL := url.GenerateShortURL(originalURL) - return shortURL - } else { - // 自己是主节点 - shortURL := url.GenerateShortURL(originalURL) - // 使用getBaseURL函数来获取baseUrl并与shortURL组合 - return url.GetBaseURL() + "/url/" + shortURL - } - }) + // 根据配置处理URL + if config.GetLotusValue() { + // 连接到另一个gensokyo + shortURL := url.GenerateShortURL(originalURL) + return shortURL + } else { + // 自己是主节点 + shortURL := url.GenerateShortURL(originalURL) + // 使用getBaseURL函数来获取baseUrl并与shortURL组合 + return url.GetBaseURL() + "/url/" + shortURL + } + }) + } return messageText } diff --git a/template/config_template.go b/template/config_template.go index 47cf5b9f..bd115425 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -60,9 +60,10 @@ settings: #SSL配置类 机器人发送URL设置 - identify_file: true #自动生成域名校验文件,在q.qq.com配置信息URL,在server_dir填入自己已备案域名,正确解析到机器人所在服务器ip地址,机器人即可发送链接 - crt: "" #证书路径 从你的域名服务商或云服务商申请签发SSL证书(qq要求SSL) - key: "" #密钥路径 Apache(crt文件、key文件)示例: "C:\\123.key" \需要双写成\\ + identify_file : true #自动生成域名校验文件,在q.qq.com配置信息URL,在server_dir填入自己已备案域名,正确解析到机器人所在服务器ip地址,机器人即可发送链接 + crt : "" #证书路径 从你的域名服务商或云服务商申请签发SSL证书(qq要求SSL) + key : "" #密钥路径 Apache(crt文件、key文件)示例: "C:\\123.key" \需要双写成\\ + transfer_url : true #默认开启,关闭后自理url发送,配置server_dir为你的域名,配置crt和key后,将域名/url和/image在q.qq.com后台通过校验,自动使用302跳转处理机器人发出的所有域名. #日志类 diff --git a/template/config_template.yml b/template/config_template.yml index 6565cfa9..5fae8c06 100644 --- a/template/config_template.yml +++ b/template/config_template.yml @@ -82,4 +82,5 @@ settings: reconnect_times : 100 #反向ws连接失败后的重试次数,希望一直重试,可设置9999 heart_beat_interval : 10 #反向ws心跳间隔 单位秒 推荐5-10 launch_reconnect_times : 1 #启动时尝试反向ws连接次数,建议先打开应用端再开启gensokyo,因为启动时连接会阻塞webui启动,默认只连接一次,可自行增大 - white_bypass : [] #格式[1,2,3],白名单不生效的群,用于设置自己的灰度沙箱,避免测试时候反复开关白名单的不便. \ No newline at end of file + white_bypass : [] #格式[1,2,3],白名单不生效的群,用于设置自己的灰度沙箱,避免测试时候反复开关白名单的不便. + transfer_url : true #默认开启,关闭后自理url发送,配置server_dir为你的域名,配置crt和key后,将域名/url和/image在q.qq.com后台通过校验,自动使用302跳转处理机器人发出的所有域名.