mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
fix(drawlots): draw gif noise
This commit is contained in:
parent
63784b4ed0
commit
803c027264
@ -13,6 +13,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
fcext "github.com/FloatTech/floatbox/ctxext"
|
||||||
"github.com/FloatTech/floatbox/file"
|
"github.com/FloatTech/floatbox/file"
|
||||||
"github.com/FloatTech/floatbox/web"
|
"github.com/FloatTech/floatbox/web"
|
||||||
"github.com/FloatTech/imgfactory"
|
"github.com/FloatTech/imgfactory"
|
||||||
@ -90,7 +91,7 @@ func init() {
|
|||||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("file:///"+picPath))
|
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("file:///"+picPath))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lotsImg, err := randGif(lotsType + "." + fileInfo.lotsType)
|
lotsImg, err := randGif(lotsType+"."+fileInfo.lotsType, ctx.Event.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
return
|
return
|
||||||
@ -229,7 +230,7 @@ func randFile(path string, indexMax int) (string, error) {
|
|||||||
return "", errors.New("图包[" + path + "]不存在签内容!")
|
return "", errors.New("图包[" + path + "]不存在签内容!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func randGif(gifName string) (image.Image, error) {
|
func randGif(gifName string, uid int64) (image.Image, error) {
|
||||||
name := datapath + gifName
|
name := datapath + gifName
|
||||||
file, err := os.Open(name)
|
file, err := os.Open(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -264,13 +265,13 @@ func randGif(gifName string) (image.Image, error) {
|
|||||||
rect.Max = max
|
rect.Max = max
|
||||||
}
|
}
|
||||||
img := image.NewRGBA(rect)
|
img := image.NewRGBA(rect)
|
||||||
b := rand.Intn(len(im.Image)) + 1
|
b := fcext.RandSenderPerDayN(uid, len(im.Image)) + 1
|
||||||
a := 0
|
a := 0
|
||||||
if b > 8 {
|
if b > 8 {
|
||||||
a = b - 8
|
a = b - 8
|
||||||
}
|
}
|
||||||
for _, srcimg := range im.Image[a:b] {
|
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
|
return img, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,7 @@ func init() {
|
|||||||
enc := base64.NewEncoder(base64.StdEncoding, buf)
|
enc := base64.NewEncoder(base64.StdEncoding, buf)
|
||||||
_, err := io.Copy(enc, resp.Body)
|
_, err := io.Copy(enc, resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logrus.Warnln("[emojimix] copy err:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = enc.Close()
|
_ = enc.Close()
|
||||||
@ -52,7 +53,7 @@ func init() {
|
|||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err = http2.Head(u2)
|
resp, err = http2.Get(u2)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
send(resp)
|
send(resp)
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user