Skip to content

Commit ba4ca11

Browse files
🎨增加文字回复 (#205)
* 🎨增加文字回复 * 🎨增加文字回复 * 🎨增加文字回复 * 🎨增加文字回复(fix) * 🎨small letter=> * Update ys.go * Update ys.go * Update ys.go Co-authored-by: 源文雨 <[email protected]>
1 parent 9372902 commit ba4ca11

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

plugin/genshin/ys.go

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"image/jpeg"
1010
"image/png"
1111
"math/rand"
12+
"regexp"
1213
"strings"
1314
"sync/atomic"
1415

@@ -29,6 +30,7 @@ var (
2930
totl uint64 // 累计抽奖次数
3031
filetree = make(zipfilestructure, 32)
3132
starN3, starN4, starN5 *zip.File
33+
namereg = regexp.MustCompile(`_(.*)\.png`)
3234
)
3335

3436
func init() {
@@ -91,18 +93,24 @@ func init() {
9193
gid = -ctx.Event.UserID
9294
}
9395
store := (storage)(c.GetData(gid))
94-
img, err := randnums(10, store)
96+
img, str, mode, err := randnums(10, store)
9597
if err != nil {
9698
ctx.SendChain(message.Text("ERROR:", err))
9799
return
98100
}
99101
b, cl := writer.ToBytes(img)
100-
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.ImageBytes(b)))
102+
if mode {
103+
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID,
104+
message.Text("恭喜你抽到了: \n", str), message.ImageBytes(b)))
105+
} else {
106+
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID,
107+
message.Text("十连成功~"), message.ImageBytes(b)))
108+
}
101109
cl()
102110
})
103111
}
104112

105-
func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
113+
func randnums(nums int, store storage) (rgba *image.RGBA, str string, replyMode bool, err error) {
106114
var (
107115
fours, fives = make([]*zip.File, 0, 10), make([]*zip.File, 0, 10) // 抽到 四, 五星角色
108116
threeArms, fourArms, fiveArms = make([]*zip.File, 0, 10), make([]*zip.File, 0, 10), make([]*zip.File, 0, 10) // 抽到 三 , 四, 五星武器
@@ -145,18 +153,18 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
145153
}
146154
} else { // 默认模式
147155
for i := 0; i < nums; i++ {
148-
a := rand.Intn(1000)
149-
switch { // 抽卡几率 三星75% 四星18% 五星7%
150-
case a >= 0 && a <= 750:
156+
a := rand.Intn(1000) // 抽卡几率 三星80% 四星17% 五星3%
157+
switch {
158+
case a >= 0 && a <= 800:
151159
threeN2++
152160
threeArms = append(threeArms, filetree["Three"][rand.Intn(threelen)])
153-
case a > 750 && a <= 840:
161+
case a > 800 && a <= 885:
154162
fourN++
155163
fours = append(fours, filetree["four"][rand.Intn(fourlen)]) // 随机角色
156-
case a > 840 && a <= 930:
164+
case a > 885 && a <= 970:
157165
fourN2++
158166
fourArms = append(fourArms, filetree["four2"][rand.Intn(four2len)]) // 随机武器
159-
case a > 930 && a <= 965:
167+
case a > 970 && a <= 985:
160168
fiveN++
161169
fives = append(fives, filetree["five"][rand.Intn(fivelen)])
162170
default:
@@ -210,12 +218,16 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
210218

211219
if fiveN > 0 { // 按顺序加入
212220
he(fiveN, 5, starN5, fivebg) // 五星角色
221+
str += reply(fives, 1, str)
222+
replyMode = true
213223
}
214224
if fourN > 0 {
215225
he(fourN, 3, starN4, fourbg) // 四星角色
216226
}
217227
if fiveN2 > 0 {
218228
he(fiveN2, 4, starN5, fivebg) // 五星武器
229+
str += reply(fiveArms, 2, str)
230+
replyMode = true
219231
}
220232
if fourN2 > 0 {
221233
he(fourN2, 2, starN4, fourbg) // 四星武器
@@ -256,7 +268,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
256268

257269
imgs, err := bgs[i].Open() // 取出背景图片
258270
if err != nil {
259-
return nil, err
271+
return nil, "", false, err
260272
}
261273
defer imgs.Close()
262274

@@ -266,7 +278,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
266278

267279
imgs1, err := hero[i].Open() // 取出图片名
268280
if err != nil {
269-
return nil, err
281+
return nil, "", false, err
270282
}
271283
defer imgs1.Close()
272284

@@ -276,7 +288,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
276288

277289
imgs2, err := stars[i].Open() // 取出星级图标
278290
if err != nil {
279-
return nil, err
291+
return nil, "", false, err
280292
}
281293
defer imgs2.Close()
282294

@@ -286,7 +298,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
286298

287299
imgs3, err := cicon[i].Open() // 取出类型图标
288300
if err != nil {
289-
return nil, err
301+
return nil, "", false, err
290302
}
291303
defer imgs3.Close()
292304

@@ -296,12 +308,12 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
296308
}
297309
imgs4, err := filetree["Reply.png"][0].Open() // "分享" 图标
298310
if err != nil {
299-
return nil, err
311+
return nil, "", false, err
300312
}
301313
defer imgs4.Close()
302314
img4, err := png.Decode(imgs4)
303315
if err != nil {
304-
return nil, err
316+
return nil, "", false, err
305317
}
306318
offset4 := image.Pt(1270, 945) // 宽, 高
307319
draw.Draw(rgba, img4.Bounds().Add(offset4), img4, image.Point{}, draw.Over)
@@ -343,3 +355,21 @@ func parsezip(zipFile string) error {
343355
}
344356
return nil
345357
}
358+
359+
// 取出角色武器名
360+
func reply(z []*zip.File, num int, nameStr string) string {
361+
var tmp strings.Builder
362+
tmp.Grow(128)
363+
switch {
364+
case num == 1:
365+
tmp.WriteString("★五星角色★\n")
366+
case num == 2 && len(nameStr) > 0:
367+
tmp.WriteString("\n★五星武器★\n")
368+
default:
369+
tmp.WriteString("★五星武器★\n")
370+
}
371+
for i := range z {
372+
tmp.WriteString(namereg.FindStringSubmatch(z[i].Name)[1] + " * ")
373+
}
374+
return tmp.String()
375+
}

0 commit comments

Comments
 (0)