mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
词库增加设置概率功能
This commit is contained in:
parent
83778afd51
commit
3b1ad2250f
@ -252,6 +252,7 @@ zerobot [-h] [-n nickname] [-t token] [-u url] [-p prefix] [-d|w] [-c|s config.j
|
||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/thesaurus"`
|
||||
|
||||
- [x] 切换[kimo|傲娇|可爱]词库
|
||||
- [x] 设置词库触发概率0.x (0<x<9)
|
||||
|
||||
</details>
|
||||
<details>
|
||||
|
||||
@ -21,7 +21,7 @@ func init() {
|
||||
engine := control.Register("thesaurus", &ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "词典匹配回复",
|
||||
Help: "- 切换[kimo|傲娇|可爱]词库",
|
||||
Help: "- 切换[kimo|傲娇|可爱]词库\n- 设置词库触发概率0.x (0<x<9)",
|
||||
PublicDataFolder: "Chat",
|
||||
})
|
||||
engine.OnRegex(`^切换(kimo|傲娇|可爱)词库$`, zero.AdminPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
@ -34,15 +34,40 @@ func init() {
|
||||
if gid == 0 {
|
||||
gid = -ctx.Event.UserID
|
||||
}
|
||||
var err error
|
||||
d := c.GetData(gid)
|
||||
t := int64(0)
|
||||
switch ctx.State["regex_matched"].([]string)[1] {
|
||||
case "kimo":
|
||||
err = c.SetData(gid, tKIMO)
|
||||
t = tKIMO
|
||||
case "傲娇":
|
||||
err = c.SetData(gid, tDERE)
|
||||
t = tDERE
|
||||
case "可爱":
|
||||
err = c.SetData(gid, tKAWA)
|
||||
t = tKAWA
|
||||
}
|
||||
err := c.SetData(gid, (d&^3)|t)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
})
|
||||
engine.OnRegex(`^设置词库触发概率\s*0.(\d)$`, zero.AdminPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
|
||||
if !ok {
|
||||
ctx.SendChain(message.Text("ERROR: 找不到 manager"))
|
||||
return
|
||||
}
|
||||
n := ctx.State["regex_matched"].([]string)[1][0] - '0'
|
||||
if n <= 0 || n >= 9 {
|
||||
ctx.SendChain(message.Text("ERROR: 概率越界"))
|
||||
return
|
||||
}
|
||||
n-- // 0~7
|
||||
gid := ctx.Event.GroupID
|
||||
if gid == 0 {
|
||||
gid = -ctx.Event.UserID
|
||||
}
|
||||
d := c.GetData(gid)
|
||||
err := c.SetData(gid, (d&3)|(int64(n)<<59))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
@ -142,6 +167,9 @@ const (
|
||||
|
||||
func canmatch(typ int64) zero.Rule {
|
||||
return func(ctx *zero.Ctx) bool {
|
||||
if zero.HasPicture(ctx) {
|
||||
return false
|
||||
}
|
||||
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
|
||||
if !ok {
|
||||
return false
|
||||
@ -150,7 +178,8 @@ func canmatch(typ int64) zero.Rule {
|
||||
if gid == 0 {
|
||||
gid = -ctx.Event.UserID
|
||||
}
|
||||
return c.GetData(gid) == typ
|
||||
d := c.GetData(gid)
|
||||
return d&3 == typ && rand.Int63n(10) <= d>>59
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user