diff --git a/go.mod b/go.mod index fdd530c..4b1b387 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/FloatTech/ZeroBot-Plugin-Webui v1.0.1-0.20230412164529-cfe878675931 - github.com/FloatTech/floatbox v0.0.0-20240502092157-9deaab837c04 + github.com/FloatTech/floatbox v0.0.0-20240504085530-b2994112ec50 github.com/FloatTech/gg v1.1.2 github.com/FloatTech/imgfactory v0.2.2-0.20230315152233-49741fc994f9 github.com/FloatTech/rendercard v0.0.10-0.20230223064326-45d29fa4ede9 diff --git a/go.sum b/go.sum index 70a26b7..d2f272d 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/FloatTech/ZeroBot-Plugin-Webui v1.0.1-0.20230412164529-cfe878675931 h1:jTc1mb2sG1krnxpgD75SMojeOMIl6bGX5t3YGIRKkHI= github.com/FloatTech/ZeroBot-Plugin-Webui v1.0.1-0.20230412164529-cfe878675931/go.mod h1:Se2A9vnC4eSYF7vR2LNSayV7rvbFcpgVs1ZN4sEYMyg= -github.com/FloatTech/floatbox v0.0.0-20240502092157-9deaab837c04 h1:qTlD6NN7+NMuxr4p2C4E0VUITh+ikIwLx7Z0nKCF3Kc= -github.com/FloatTech/floatbox v0.0.0-20240502092157-9deaab837c04/go.mod h1:OzGLhvmtz1TKIdGaJDd8pQumvD36UqK+dWsiCISmzQQ= +github.com/FloatTech/floatbox v0.0.0-20240504085530-b2994112ec50 h1:1D9BS5nI8UFQ8dg3QJicntfGbtL5WdZsKm/OMyBd/lM= +github.com/FloatTech/floatbox v0.0.0-20240504085530-b2994112ec50/go.mod h1:OzGLhvmtz1TKIdGaJDd8pQumvD36UqK+dWsiCISmzQQ= github.com/FloatTech/gg v1.1.2 h1:YolgOYg3uDHc1+g0bLtt6QuRA/pvLn+b9IBCIhOOX88= github.com/FloatTech/gg v1.1.2/go.mod h1:uzPzAeT35egARdRuu+1oyjU3CmTwCceoq3Vvje7LpcI= github.com/FloatTech/imgfactory v0.2.2-0.20230315152233-49741fc994f9 h1:IzZLuM/fgKclyMaU/Qb1qlLdGrs2FTietkqOWhh07Gw= diff --git a/img/pool/img.go b/img/pool/img.go index a7b97e8..6a680ca 100644 --- a/img/pool/img.go +++ b/img/pool/img.go @@ -63,7 +63,7 @@ func GetImage(name string) (m *Image, err error) { } // NewImage context name file -func NewImage(send ctxext.NoCtxSendMsg, get ctxext.NoCtxGetMsg, name, f string) (m *Image, hassent bool, err error) { +func NewImage(send ctxext.NoCtxSendMsg, get ctxext.NoCtxGetMsg, name, f string) (m *Image, err error) { m = new(Image) m.n = name m.SetFile(f) @@ -80,7 +80,7 @@ func NewImage(send ctxext.NoCtxSendMsg, get ctxext.NoCtxGetMsg, name, f string) logrus.Debugln("[imgpool] image", name, m, "outdated, updating...") get = nil } - hassent, err = m.Push(send, get) + err = m.Push(send, get) return } @@ -109,60 +109,34 @@ func (m *Image) SetFile(f string) { } // Push context -func (m *Image) Push(send ctxext.NoCtxSendMsg, get ctxext.NoCtxGetMsg) (hassent bool, err error) { +func (m *Image) Push(send ctxext.NoCtxSendMsg, get ctxext.NoCtxGetMsg) (err error) { id := send(message.Message{message.Image(m.f)}) if id == 0 { err = ErrSendImg return } - hassent = true - if get != nil { - msg := get(id) - for _, e := range msg.Elements { - if e.Type == "image" { - u := e.Data["url"] - if ntcachere.MatchString(u) { // is NTQQ - raw := "" - raw, err = nturl(u).pack() - if err != nil { - logrus.Errorln("[imgpool] pack nturl err:", err) - err = nil - return - } - m.item, err = newItem(m.n, raw) - if err != nil { - logrus.Errorln("[imgpool] get newItem err:", err) - err = nil - return - } - logrus.Debugln("[imgpool] 缓存:", m.n, "url:", u) - err = m.item.push("minamoto") - if err != nil { - logrus.Errorln("[imgpool] item.push err:", err) - err = nil - } + if get == nil { + return + } + msg := get(id) + for _, e := range msg.Elements { + if e.Type == "image" { + u := e.Data["url"] + if ntcachere.MatchString(u) { // is NTQQ + raw := "" + raw, err = nturl(u).pack() + if err != nil { + logrus.Errorln("[imgpool] pack nturl err:", err) + err = nil return } - i := strings.LastIndex(u, "/") - if i <= 0 { - break - } - u = u[:i] - i = strings.LastIndex(u, "-") - if i <= 0 { - break - } - u = u[i:] - if u == "" { - break - } - m.item, err = newItem(m.n, "0-0"+u) + m.item, err = newItem(m.n, raw) if err != nil { logrus.Errorln("[imgpool] get newItem err:", err) err = nil return } - logrus.Debugln("[imgpool] 缓存:", m.n, "url:", "0-0"+u) + logrus.Debugln("[imgpool] 缓存:", m.n, "url:", u) err = m.item.push("minamoto") if err != nil { logrus.Errorln("[imgpool] item.push err:", err) @@ -170,8 +144,34 @@ func (m *Image) Push(send ctxext.NoCtxSendMsg, get ctxext.NoCtxGetMsg) (hassent } return } + i := strings.LastIndex(u, "/") + if i <= 0 { + break + } + u = u[:i] + i = strings.LastIndex(u, "-") + if i <= 0 { + break + } + u = u[i:] + if u == "" { + break + } + m.item, err = newItem(m.n, "0-0"+u) + if err != nil { + logrus.Errorln("[imgpool] get newItem err:", err) + err = nil + return + } + logrus.Debugln("[imgpool] 缓存:", m.n, "url:", "0-0"+u) + err = m.item.push("minamoto") + if err != nil { + logrus.Errorln("[imgpool] item.push err:", err) + err = nil + } + return } - err = ErrGetMsg } + err = ErrGetMsg return } diff --git a/img/pool/sender.go b/img/pool/sender.go index 82fa234..0378901 100644 --- a/img/pool/sender.go +++ b/img/pool/sender.go @@ -23,16 +23,7 @@ func SendImageFromPool(imgname, imgpath string, genimg func() error, send ctxext } } m.SetFile(file.BOTPATH + "/" + imgpath) - if err == ErrImgFileOutdated { - get = nil - } - hassent, err := m.Push(send, get) - if hassent { - return nil - } - if err != nil { - return err - } + return m.Push(send, get) } // 发送图片 img := message.Image(m.String()) @@ -55,13 +46,7 @@ func SendRemoteImageFromPool(imgname, imgurl string, send ctxext.NoCtxSendMsg, g if err == ErrImgFileOutdated { get = nil } - hassent, err := m.Push(send, get) - if hassent { - return nil - } - if err != nil { - return err - } + return m.Push(send, get) } // 发送图片 img := message.Image(m.String())