mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 19:43:49 +08:00
try to support escape again. #9
This commit is contained in:
parent
5683db6324
commit
bb03315930
@ -118,13 +118,13 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
|||||||
if ur {
|
if ur {
|
||||||
r += fmt.Sprintf(`[CQ:record,file=%s]`, o.Name)
|
r += fmt.Sprintf(`[CQ:record,file=%s]`, o.Name)
|
||||||
} else {
|
} 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:
|
case *message.ImageElement:
|
||||||
if ur {
|
if ur {
|
||||||
r += fmt.Sprintf(`[CQ:image,file=%s]`, o.Filename)
|
r += fmt.Sprintf(`[CQ:image,file=%s]`, o.Filename)
|
||||||
} else {
|
} 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)
|
ps := paramReg.FindAllStringSubmatch(code, -1)
|
||||||
d := make(map[string]string)
|
d := make(map[string]string)
|
||||||
for _, p := range ps {
|
for _, p := range ps {
|
||||||
d[p[1]] = p[2]
|
d[p[1]] = CQCodeUnescapeValue(p[2])
|
||||||
}
|
}
|
||||||
if t == "reply" && group {
|
if t == "reply" && group {
|
||||||
if len(r) > 0 {
|
if len(r) > 0 {
|
||||||
@ -399,6 +399,12 @@ func CQCodeEscapeText(raw string) string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CQCodeEscapeValue(value string) string {
|
||||||
|
ret := CQCodeEscapeText(value)
|
||||||
|
ret = strings.ReplaceAll(ret, ",", ",")
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func CQCodeUnescapeText(content string) string {
|
func CQCodeUnescapeText(content string) string {
|
||||||
ret := content
|
ret := content
|
||||||
ret = strings.ReplaceAll(ret, "[", "[")
|
ret = strings.ReplaceAll(ret, "[", "[")
|
||||||
@ -406,3 +412,9 @@ func CQCodeUnescapeText(content string) string {
|
|||||||
ret = strings.ReplaceAll(ret, "&", "&")
|
ret = strings.ReplaceAll(ret, "&", "&")
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CQCodeUnescapeValue(content string) string {
|
||||||
|
ret := CQCodeUnescapeText(content)
|
||||||
|
ret = strings.ReplaceAll(ret, ",", ",")
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user