-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
90 lines (81 loc) · 2.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package reborn
import (
"encoding/json"
"fmt"
"math/rand"
"os"
"time"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/MoYoez/Lucy_reibot/utils/toolchain"
"github.com/MoYoez/Lucy_reibot/utils/transform"
rei "github.com/fumiama/ReiBot"
wr "github.com/mroth/weightedrand"
"github.com/sirupsen/logrus"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
)
var (
areac *wr.Chooser
gender, _ = wr.NewChooser(
wr.Choice{Item: "男孩子", Weight: 23707},
wr.Choice{Item: "女孩子", Weight: 49292},
wr.Choice{Item: "雌雄同体", Weight: 1001},
wr.Choice{Item: "猫猫!", Weight: 15000},
wr.Choice{Item: "狗狗!", Weight: 5000},
wr.Choice{Item: "龙猫~", Weight: 6000},
)
rebornTimerManager = rate.NewManager[int64](time.Minute*2, 5)
)
type ratego []struct {
Name string `json:"name"`
Weight float64 `json:"weight"`
}
func init() {
engine := rei.Register("reborn", &ctrl.Options[*rei.Ctx]{
DisableOnDefault: false,
Help: "reborn",
})
go func() {
datapath := transform.ReturnLucyMainDataIndex("funwork")
jsonfile := datapath + "ratego.json"
area := make(ratego, 226)
err := load(&area, jsonfile)
if err != nil {
return
}
choices := make([]wr.Choice, len(area))
for i, a := range area {
choices[i].Item = a.Name
choices[i].Weight = uint(a.Weight * 1e9)
}
areac, err = wr.NewChooser(choices...)
if err != nil {
return
}
logrus.Printf("[Reborn]读取%d个国家/地区", len(area))
}()
engine.OnMessageCommand("reborn").SetBlock(true).Handle(func(ctx *rei.Ctx) {
if !rebornTimerManager.Load(toolchain.GetThisGroupID(ctx)).Acquire() {
ctx.SendPlainMessage(true, "太快了哦,麻烦慢一点~")
return
}
if rand.Int31() > 1<<27 {
ctx.SendPlainMessage(true, fmt.Sprintf("投胎成功!\n您出生在 %s, 是 %s。", randcoun(), randgen()))
} else {
ctx.SendPlainMessage(true, "投胎失败!\n您没能活到出生,希望下次运气好一点呢~!")
}
})
}
// load 加载rate数据
func load(area *ratego, jsonfile string) error {
data, err := os.ReadFile(jsonfile)
if err != nil {
return err
}
return json.Unmarshal(data, area)
}
func randcoun() string {
return areac.Pick().(string)
}
func randgen() string {
return gender.Pick().(string)
}