Commit bb033159 authored by Mrs4s's avatar Mrs4s

try to support escape again. #9

parent 5683db63
......@@ -118,13 +118,13 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
if ur {
r += fmt.Sprintf(`[CQ:record,file=%s]`, o.Name)
} else {
r += fmt.Sprintf(`[CQ:record,file=%s,url=%s]`, o.Name, o.Url)
r += fmt.Sprintf(`[CQ:record,file=%s,url=%s]`, o.Name, CQCodeEscapeValue(o.Url))
}
case *message.ImageElement:
if ur {
r += fmt.Sprintf(`[CQ:image,file=%s]`, o.Filename)
} else {
r += fmt.Sprintf(`[CQ:image,file=%s,url=%s]`, o.Filename, o.Url)
r += fmt.Sprintf(`[CQ:image,file=%s,url=%s]`, o.Filename, CQCodeEscapeValue(o.Url))
}
}
}
......@@ -145,7 +145,7 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
ps := paramReg.FindAllStringSubmatch(code, -1)
d := make(map[string]string)
for _, p := range ps {
d[p[1]] = p[2]
d[p[1]] = CQCodeUnescapeValue(p[2])
}
if t == "reply" && group {
if len(r) > 0 {
......@@ -399,6 +399,12 @@ func CQCodeEscapeText(raw string) string {
return ret
}
func CQCodeEscapeValue(value string) string {
ret := CQCodeEscapeText(value)
ret = strings.ReplaceAll(ret, ",", ",")
return ret
}
func CQCodeUnescapeText(content string) string {
ret := content
ret = strings.ReplaceAll(ret, "[", "[")
......@@ -406,3 +412,9 @@ func CQCodeUnescapeText(content string) string {
ret = strings.ReplaceAll(ret, "&", "&")
return ret
}
func CQCodeUnescapeValue(content string) string {
ret := CQCodeUnescapeText(content)
ret = strings.ReplaceAll(ret, ",", ",")
return ret
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment