Skip to content

Commit 1afe660

Browse files
authored
add DoOnceOnSuccess
1 parent 5b98ac8 commit 1afe660

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

plugin/wife/main.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,16 @@ import (
1818

1919
var (
2020
cards = []string{}
21-
re = regexp.MustCompile(`^\[(.*?)\](.*)\..*$`)
21+
re = regexp.MustCompile(`^\[(.*?)\](.*) - P\d+\..*$`)
2222
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
2323
DisableOnDefault: false,
2424
Help: "- 抽老婆",
2525
Brief: "从老婆库抽每日老婆",
2626
PublicDataFolder: "Wife",
2727
}).ApplySingle(ctxext.DefaultSingle)
28-
)
29-
30-
func card2name(card string) (string, string) {
31-
match := re.FindStringSubmatch(card)
32-
if len(match) >= 3 {
33-
return match[1], match[2]
34-
}
35-
return "", ""
36-
}
37-
38-
func init() {
39-
_ = os.MkdirAll(engine.DataFolder()+"wives", 0755)
40-
engine.OnFullMatch("抽老婆", fcext.DoOnceOnSuccess(
28+
getJson = fcext.DoOnceOnSuccess(
4129
func(ctx *zero.Ctx) bool {
42-
data, err := engine.GetLazyData("wife.json", true)
30+
data, err := engine.GetLazyData("wife.json", false)
4331
if err != nil {
4432
ctx.SendChain(message.Text("ERROR: ", err))
4533
return false
@@ -52,7 +40,20 @@ func init() {
5240
logrus.Infof("[wife]加载%d个老婆", len(cards))
5341
return true
5442
},
55-
)).SetBlock(true).
43+
)
44+
)
45+
46+
func card2name(card string) (string, string) {
47+
match := re.FindStringSubmatch(card)
48+
if len(match) >= 3 {
49+
return match[1], match[2]
50+
}
51+
return "", ""
52+
}
53+
54+
func init() {
55+
_ = os.MkdirAll(engine.DataFolder()+"wives", 0755)
56+
engine.OnFullMatch("抽老婆", getJson).SetBlock(true).
5657
Handle(func(ctx *zero.Ctx) {
5758
card := cards[fcext.RandSenderPerDayN(ctx.Event.UserID, len(cards))]
5859
data, err := engine.GetLazyData("wives/"+card, true)

plugin/wife/wifegame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
)
3030

3131
func init() {
32-
enguess.OnFullMatch("猜老婆").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
32+
enguess.OnFullMatch("猜老婆", getJson).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
3333
class := 3
3434

3535
card := cards[rand.Intn(len(cards))]

0 commit comments

Comments
 (0)