-
Notifications
You must be signed in to change notification settings - Fork 2k
/
main.go
54 lines (50 loc) · 1.54 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
// Package reborn 投胎 来自 https://github.com/YukariChiba/tgbot/blob/main/modules/Reborn.py
package reborn
import (
"fmt"
"math/rand"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
wr "github.com/mroth/weightedrand"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func init() {
en := control.Register("reborn", &control.Options{
DisableOnDefault: false,
Help: "投胎\n- reborn",
PublicDataFolder: "Reborn",
})
en.OnFullMatch("reborn", ctxext.DoOnceOnSuccess(
func(ctx *zero.Ctx) bool {
datapath := en.DataFolder()
jsonfile := datapath + "rate.json"
area := make(rate, 226)
err := load(&area, jsonfile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
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 {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
logrus.Printf("[Reborn]读取%d个国家/地区", len(area))
return true
},
)).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
if rand.Int31() > 1<<27 {
ctx.SendChain(message.At(ctx.Event.UserID), message.Text(fmt.Sprintf("投胎成功!\n您出生在 %s, 是 %s。", randcoun(), randgen())))
} else {
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("投胎失败!\n您没能活到出生,祝您下次好运!"))
}
})
}