Skip to content

Commit

Permalink
try to support escape again. #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Aug 12, 2020
1 parent 5683db6 commit bb03315
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions coolq/cqcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -399,10 +399,22 @@ 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, "[", "[")
ret = strings.ReplaceAll(ret, "]", "]")
ret = strings.ReplaceAll(ret, "&", "&")
return ret
}

func CQCodeUnescapeValue(content string) string {
ret := CQCodeUnescapeText(content)
ret = strings.ReplaceAll(ret, ",", ",")
return ret
}

0 comments on commit bb03315

Please sign in to comment.