From 0c62d8dd077202ab78bbdbaf289ef2777874f87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 10 Jun 2022 23:34:05 +0800 Subject: [PATCH] fix: imgfinder format --- plugin/image_finder/keyword.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugin/image_finder/keyword.go b/plugin/image_finder/keyword.go index d392a178..c3d35f3e 100644 --- a/plugin/image_finder/keyword.go +++ b/plugin/image_finder/keyword.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "reflect" + "regexp" "strings" "github.com/lucas-clemente/quic-go/http3" @@ -58,6 +59,8 @@ type resultjson struct { } `json:"data"` } +var hrefre = regexp.MustCompile(``) + func init() { control.Register("imgfinder", &ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, @@ -91,9 +94,9 @@ func init() { "标题: ", il.Title, "\n", "副标题: ", il.AltTitle, "\n", "ID: ", il.ID, "\n", - "画师: ", illust.UserName, "(", illust.UserId, ")", "\n", + "画师: ", illust.UserName, " (", illust.UserId, ")", "\n", "分级:", il.Sanity, "\n", - strings.ReplaceAll(il.Description, "
", "\n"), + hrefre.ReplaceAllString(strings.ReplaceAll(strings.ReplaceAll(il.Description, "
", "\n"), "
", ""), ""), printtags(reflect.ValueOf(&il.Tags)), ), ), ctxext.GetFirstMessageInForward(ctx)) @@ -127,20 +130,16 @@ func printtags(r reflect.Value) string { tags := r.Elem() s := binary.BytesToString(binary.NewWriterF(func(w *binary.Writer) { for i := 0; i < tags.Len(); i++ { + w.WriteByte('\n') tag := tags.Index(i) _ = w.WriteByte('#') w.WriteString(tag.Field(0).String()) if !tag.Field(1).IsZero() { w.WriteString(" (") w.WriteString(tag.Field(1).String()) - w.WriteString(")\n") - } else { - w.WriteByte('\n') + w.WriteString(")") } } })) - if len(s) > 0 { - s = s[:len(s)-1] - } return s }