From 803c027264ab8ab6ac17e0f3795d3613183921c2 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: Thu, 2 May 2024 22:48:06 +0900 Subject: [PATCH] fix(drawlots): draw gif noise --- plugin/drawlots/main.go | 9 +++++---- plugin/emojimix/mix.go | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugin/drawlots/main.go b/plugin/drawlots/main.go index e3c8af1c..67edaea2 100644 --- a/plugin/drawlots/main.go +++ b/plugin/drawlots/main.go @@ -13,6 +13,7 @@ import ( "strconv" "strings" + fcext "github.com/FloatTech/floatbox/ctxext" "github.com/FloatTech/floatbox/file" "github.com/FloatTech/floatbox/web" "github.com/FloatTech/imgfactory" @@ -90,7 +91,7 @@ func init() { ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("file:///"+picPath)) return } - lotsImg, err := randGif(lotsType + "." + fileInfo.lotsType) + lotsImg, err := randGif(lotsType+"."+fileInfo.lotsType, ctx.Event.UserID) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -229,7 +230,7 @@ func randFile(path string, indexMax int) (string, error) { return "", errors.New("图包[" + path + "]不存在签内容!") } -func randGif(gifName string) (image.Image, error) { +func randGif(gifName string, uid int64) (image.Image, error) { name := datapath + gifName file, err := os.Open(name) if err != nil { @@ -264,13 +265,13 @@ func randGif(gifName string) (image.Image, error) { rect.Max = max } img := image.NewRGBA(rect) - b := rand.Intn(len(im.Image)) + 1 + b := fcext.RandSenderPerDayN(uid, len(im.Image)) + 1 a := 0 if b > 8 { a = b - 8 } for _, srcimg := range im.Image[a:b] { - draw.Draw(img, srcimg.Bounds(), srcimg, srcimg.Rect.Min, draw.Src) + draw.Draw(img, srcimg.Bounds(), srcimg, srcimg.Rect.Min, draw.Over) } return img, err } diff --git a/plugin/emojimix/mix.go b/plugin/emojimix/mix.go index 6fbf8b42..1f322bb0 100644 --- a/plugin/emojimix/mix.go +++ b/plugin/emojimix/mix.go @@ -41,6 +41,7 @@ func init() { enc := base64.NewEncoder(base64.StdEncoding, buf) _, err := io.Copy(enc, resp.Body) if err != nil { + logrus.Warnln("[emojimix] copy err:", err) return } _ = enc.Close() @@ -52,7 +53,7 @@ func init() { _ = resp.Body.Close() return } - resp, err = http2.Head(u2) + resp, err = http2.Get(u2) if err == nil { send(resp) _ = resp.Body.Close()