Skip to content

Commit

Permalink
fix(drawlots): draw gif noise
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed May 2, 2024
1 parent 63784b4 commit 803c027
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions plugin/drawlots/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion plugin/emojimix/mix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 803c027

Please sign in to comment.