Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta84 #227

Merged
merged 15 commits into from
Dec 6, 2023
14 changes: 14 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -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
}

47 changes: 25 additions & 22 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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跳转处理机器人发出的所有域名.

#日志类

Expand Down
3 changes: 2 additions & 1 deletion template/config_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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],白名单不生效的群,用于设置自己的灰度沙箱,避免测试时候反复开关白名单的不便.
white_bypass : [] #格式[1,2,3],白名单不生效的群,用于设置自己的灰度沙箱,避免测试时候反复开关白名单的不便.
transfer_url : true #默认开启,关闭后自理url发送,配置server_dir为你的域名,配置crt和key后,将域名/url和/image在q.qq.com后台通过校验,自动使用302跳转处理机器人发出的所有域名.
Loading