Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiang-Red committed Apr 27, 2022
2 parents d5331ee + ba4ca11 commit 346973d
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions plugin/genshin/ys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"image/jpeg"
"image/png"
"math/rand"
"regexp"
"strings"
"sync/atomic"
"time"
Expand All @@ -31,6 +32,7 @@ var (
totl uint64 // 累计抽奖次数
filetree = make(zipfilestructure, 32)
starN3, starN4, starN5 *zip.File
namereg = regexp.MustCompile(`_(.*)\.png`)
limit = rate.NewManager[int64](time.Hour, 5)
)

Expand Down Expand Up @@ -66,7 +68,6 @@ func init() {
ctx.SendChain(message.Text("ERROR:", err))
}
})

engine.OnFullMatch("原神十连", ctxext.DoOnceOnSuccess(
func(ctx *zero.Ctx) bool {
zipfile := engine.DataFolder() + "Genshin.zip"
Expand Down Expand Up @@ -95,21 +96,27 @@ func init() {
gid = -ctx.Event.UserID
}
store := (storage)(c.GetData(gid))
img, err := randnums(10, store)
img, str, mode, err := randnums(10, store)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
b, cl := writer.ToBytes(img)
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.ImageBytes(b)))
if mode {
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID,
message.Text("恭喜你抽到了: \n", str), message.ImageBytes(b)))
} else {
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID,
message.Text("十连成功~"), message.ImageBytes(b)))
}
cl()
} else {
ctx.SendChain(message.Text("一小时五次哟"))
}
})
}

func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
func randnums(nums int, store storage) (rgba *image.RGBA, str string, replyMode bool, err error) {
var (
fours, fives = make([]*zip.File, 0, 10), make([]*zip.File, 0, 10) // 抽到 四, 五星角色
threeArms, fourArms, fiveArms = make([]*zip.File, 0, 10), make([]*zip.File, 0, 10), make([]*zip.File, 0, 10) // 抽到 三 , 四, 五星武器
Expand Down Expand Up @@ -217,12 +224,16 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {

if fiveN > 0 { // 按顺序加入
he(fiveN, 5, starN5, fivebg) // 五星角色
str += reply(fives, 1, str)
replyMode = true
}
if fourN > 0 {
he(fourN, 3, starN4, fourbg) // 四星角色
}
if fiveN2 > 0 {
he(fiveN2, 4, starN5, fivebg) // 五星武器
str += reply(fiveArms, 2, str)
replyMode = true
}
if fourN2 > 0 {
he(fourN2, 2, starN4, fourbg) // 四星武器
Expand Down Expand Up @@ -263,7 +274,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {

imgs, err := bgs[i].Open() // 取出背景图片
if err != nil {
return nil, err
return nil, "", false, err
}
defer imgs.Close()

Expand All @@ -273,7 +284,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {

imgs1, err := hero[i].Open() // 取出图片名
if err != nil {
return nil, err
return nil, "", false, err
}
defer imgs1.Close()

Expand All @@ -283,7 +294,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {

imgs2, err := stars[i].Open() // 取出星级图标
if err != nil {
return nil, err
return nil, "", false, err
}
defer imgs2.Close()

Expand All @@ -293,7 +304,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {

imgs3, err := cicon[i].Open() // 取出类型图标
if err != nil {
return nil, err
return nil, "", false, err
}
defer imgs3.Close()

Expand All @@ -303,12 +314,12 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
}
imgs4, err := filetree["Reply.png"][0].Open() // "分享" 图标
if err != nil {
return nil, err
return nil, "", false, err
}
defer imgs4.Close()
img4, err := png.Decode(imgs4)
if err != nil {
return nil, err
return nil, "", false, err
}
offset4 := image.Pt(1270, 945) // 宽, 高
draw.Draw(rgba, img4.Bounds().Add(offset4), img4, image.Point{}, draw.Over)
Expand Down Expand Up @@ -350,3 +361,21 @@ func parsezip(zipFile string) error {
}
return nil
}

// 取出角色武器名
func reply(z []*zip.File, num int, nameStr string) string {
var tmp strings.Builder
tmp.Grow(128)
switch {
case num == 1:
tmp.WriteString("★五星角色★\n")
case num == 2 && len(nameStr) > 0:
tmp.WriteString("\n★五星武器★\n")
default:
tmp.WriteString("★五星武器★\n")
}
for i := range z {
tmp.WriteString(namereg.FindStringSubmatch(z[i].Name)[1] + " * ")
}
return tmp.String()
}

0 comments on commit 346973d

Please sign in to comment.