This commit is contained in:
cdle
2021-10-23 14:08:21 +08:00
parent 87775e34fd
commit 8578c9b787
+2 -3
View File
@@ -284,14 +284,13 @@ func (sender *Sender) Reply(msgs ...interface{}) (int, error) {
} }
paths := []string{} paths := []string{}
for _, v := range regexp.MustCompile(`\[CQ:image,file=([^\[\]]+)\]`).FindAllStringSubmatch(message, -1) { for _, v := range regexp.MustCompile(`\[CQ:image,file=([^\[\]]+)\]`).FindAllStringSubmatch(message, -1) {
paths = append(paths, "data/images/"+v[1]) paths = append(paths, v[1])
message = strings.Replace(message, fmt.Sprintf(`[CQ:image,file=%s]`, v[1]), "", -1) message = strings.Replace(message, fmt.Sprintf(`[CQ:image,file=%s]`, v[1]), "", -1)
} }
if len(paths) > 0 { if len(paths) > 0 {
is := []tb.InputMedia{} is := []tb.InputMedia{}
for index, path := range paths { for index, path := range paths {
if strings.Contains(path, "base64") { if strings.Contains(path, "base64") {
decodeBytes, _ := base64.StdEncoding.DecodeString(path) decodeBytes, _ := base64.StdEncoding.DecodeString(path)
i := &tb.Photo{File: tb.FromReader(bytes.NewReader(decodeBytes))} i := &tb.Photo{File: tb.FromReader(bytes.NewReader(decodeBytes))}
if index == 0 { if index == 0 {
@@ -299,7 +298,7 @@ func (sender *Sender) Reply(msgs ...interface{}) (int, error) {
} }
is = append(is, i) is = append(is, i)
} else { } else {
data, err := os.ReadFile(path) data, err := os.ReadFile("data/images/" + path)
if err == nil { if err == nil {
url := regexp.MustCompile("(https.*)").FindString(string(data)) url := regexp.MustCompile("(https.*)").FindString(string(data))
if url != "" { if url != "" {