fix: imgfinder format

This commit is contained in:
源文雨 2022-06-10 23:34:05 +08:00
parent d6e352b3b4
commit 0c62d8dd07

View File

@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"reflect" "reflect"
"regexp"
"strings" "strings"
"github.com/lucas-clemente/quic-go/http3" "github.com/lucas-clemente/quic-go/http3"
@ -58,6 +59,8 @@ type resultjson struct {
} `json:"data"` } `json:"data"`
} }
var hrefre = regexp.MustCompile(`<a href=".*">`)
func init() { func init() {
control.Register("imgfinder", &ctrl.Options[*zero.Ctx]{ control.Register("imgfinder", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false, DisableOnDefault: false,
@ -91,9 +94,9 @@ func init() {
"标题: ", il.Title, "\n", "标题: ", il.Title, "\n",
"副标题: ", il.AltTitle, "\n", "副标题: ", il.AltTitle, "\n",
"ID: ", il.ID, "\n", "ID: ", il.ID, "\n",
"画师: ", illust.UserName, "(", illust.UserId, ")", "\n", "画师: ", illust.UserName, " (", illust.UserId, ")", "\n",
"分级:", il.Sanity, "\n", "分级:", il.Sanity, "\n",
strings.ReplaceAll(il.Description, "<br />", "\n"), hrefre.ReplaceAllString(strings.ReplaceAll(strings.ReplaceAll(il.Description, "<br />", "\n"), "</a>", ""), ""),
printtags(reflect.ValueOf(&il.Tags)), printtags(reflect.ValueOf(&il.Tags)),
), ),
), ctxext.GetFirstMessageInForward(ctx)) ), ctxext.GetFirstMessageInForward(ctx))
@ -127,20 +130,16 @@ func printtags(r reflect.Value) string {
tags := r.Elem() tags := r.Elem()
s := binary.BytesToString(binary.NewWriterF(func(w *binary.Writer) { s := binary.BytesToString(binary.NewWriterF(func(w *binary.Writer) {
for i := 0; i < tags.Len(); i++ { for i := 0; i < tags.Len(); i++ {
w.WriteByte('\n')
tag := tags.Index(i) tag := tags.Index(i)
_ = w.WriteByte('#') _ = w.WriteByte('#')
w.WriteString(tag.Field(0).String()) w.WriteString(tag.Field(0).String())
if !tag.Field(1).IsZero() { if !tag.Field(1).IsZero() {
w.WriteString(" (") w.WriteString(" (")
w.WriteString(tag.Field(1).String()) w.WriteString(tag.Field(1).String())
w.WriteString(")\n") w.WriteString(")")
} else {
w.WriteByte('\n')
} }
} }
})) }))
if len(s) > 0 {
s = s[:len(s)-1]
}
return s return s
} }