🐛 fix: escape markdown text
This commit is contained in:
parent
abd889c398
commit
4268f2816a
@ -61,7 +61,7 @@ func (t *Telegram) sendMessage(message string, client *requester.HTTPRequester)
|
||||
msg := telegramMessage{
|
||||
ChatID: t.chatID,
|
||||
Text: message,
|
||||
ParseMode: "Markdown",
|
||||
ParseMode: "html",
|
||||
}
|
||||
|
||||
uri := telegramURL + t.secret + "/sendMessage"
|
||||
|
@ -240,3 +240,11 @@ func GetModelsWithMatch(modelList *[]string, modelName string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func EscapeMarkdownText(text string) string {
|
||||
chars := []string{"_", "*", "[", "]", "(", ")", ">", "#", "+", "-", "=", "|", "{", "}", ".", "!", "`"}
|
||||
for _, char := range chars {
|
||||
text = strings.ReplaceAll(text, char, "\\"+char)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ func testAllChannels(isNotify bool) error {
|
||||
time.Sleep(common.RequestInterval)
|
||||
|
||||
isChannelEnabled := channel.Status == common.ChannelStatusEnabled
|
||||
sendMessage += fmt.Sprintf("**通道 %s (#%d) [%s]** : \n\n", channel.Name, channel.Id, channel.StatusToStr())
|
||||
sendMessage += fmt.Sprintf("**通道 %s - #%d - %s** : \n\n", common.EscapeMarkdownText(channel.Name), channel.Id, channel.StatusToStr())
|
||||
tik := time.Now()
|
||||
err, openaiErr := testChannel(channel, "")
|
||||
tok := time.Now()
|
||||
@ -161,7 +161,7 @@ func testAllChannels(isNotify bool) error {
|
||||
// 通道为禁用状态,并且还是请求错误 或者 响应时间超过阈值 直接跳过,也不需要更新响应时间。
|
||||
if !isChannelEnabled {
|
||||
if err != nil {
|
||||
sendMessage += fmt.Sprintf("- 测试报错: %s \n\n- 无需改变状态,跳过\n\n", err.Error())
|
||||
sendMessage += fmt.Sprintf("- 测试报错: %s \n\n- 无需改变状态,跳过\n\n", common.EscapeMarkdownText(err.Error()))
|
||||
continue
|
||||
}
|
||||
if milliseconds > disableThreshold {
|
||||
@ -187,13 +187,13 @@ func testAllChannels(isNotify bool) error {
|
||||
}
|
||||
|
||||
if ShouldDisableChannel(openaiErr, -1) {
|
||||
sendMessage += fmt.Sprintf("- 已被禁用,原因:%s\n\n", err.Error())
|
||||
sendMessage += fmt.Sprintf("- 已被禁用,原因:%s\n\n", common.EscapeMarkdownText(err.Error()))
|
||||
DisableChannel(channel.Id, channel.Name, err.Error(), false)
|
||||
continue
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
sendMessage += fmt.Sprintf("- 测试报错: %s \n\n", err.Error())
|
||||
sendMessage += fmt.Sprintf("- 测试报错: %s \n\n", common.EscapeMarkdownText(err.Error()))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user