-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
94 lines (86 loc) · 2.52 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
91
92
93
94
// Package simai refactory From Lucy For Onebot. (origin github.com/FloatTech/Zerobot-Plugin)
package simai
import (
"math/rand"
"os"
"strconv"
"strings"
"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"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"gopkg.in/yaml.v3"
)
// SimPackData simai Data
type SimPackData struct {
Proud map[string][]string `yaml:"傲娇"`
Kawaii map[string][]string `yaml:"可爱"`
}
var limit = rate.NewManager[int64](time.Minute*3, 28) // 回复限制
func init() {
engine := rei.Register("simai", &ctrl.Options[*rei.Ctx]{
DisableOnDefault: false,
PrivateDataFolder: "simai",
Help: "simai - Use simia pre-render dict to make it more clever",
})
// onload simai dict
dictLoaderLocation := transform.ReturnLucyMainDataIndex("simai") + "simai.yml"
dictLoader, err := os.ReadFile(dictLoaderLocation)
if err != nil {
return
}
var data SimPackData
_ = yaml.Unmarshal(dictLoader, &data)
engine.OnMessage(rei.OnlyToMeOrToReply).SetBlock(false).Handle(func(ctx *rei.Ctx) {
msg := ctx.Message.Text
var getChartReply []string
if GetTiredToken(ctx) < 4 {
getChartReply = data.Proud[msg]
// if no data
if getChartReply == nil {
getChartReply = data.Kawaii[msg]
if getChartReply == nil {
// no reply
return
}
}
} else {
getChartReply = data.Kawaii[msg]
// if no data
if getChartReply == nil {
getChartReply = data.Proud[msg]
if getChartReply == nil {
// no reply
return
}
}
}
if GetTiredToken(ctx) < 4 {
ctx.SendPlainMessage(true, "咱不想说话 好累awww")
return
}
GetCostTiredToken(ctx)
getReply := getChartReply[rand.Intn(len(getChartReply))]
getLucyName := []string{"Lucy", "Lucy酱"}[rand.Intn(2)]
getReply = strings.ReplaceAll(getReply, "{segment}", " ")
// get name
getUserID, getUserName := toolchain.GetChatUserInfoID(ctx)
getName := toolchain.LoadUserNickname(strconv.FormatInt(getUserID, 10))
if getName == "你" {
getName = getUserName
}
getReply = strings.ReplaceAll(getReply, "{name}", getName)
getReply = strings.ReplaceAll(getReply, "{me}", getLucyName)
ctx.SendPlainMessage(true, getReply)
})
}
func GetTiredToken(ctx *rei.Ctx) float64 {
getID, _ := toolchain.GetChatUserInfoID(ctx)
return limit.Load(getID).Tokens()
}
func GetCostTiredToken(ctx *rei.Ctx) bool {
getID, _ := toolchain.GetChatUserInfoID(ctx)
return limit.Load(getID).AcquireN(3)
}