Skip to content

Commit 9e8ae43

Browse files
authored
feat(qqwife): some onregex -> pattern (#1058)
1 parent 4ba0b36 commit 9e8ae43

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

plugin/qqwife/favorSystem.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ type favorability struct {
3131

3232
func init() {
3333
// 好感度系统
34-
engine.OnRegex(`^查好感度\s*(\[CQ:at,qq=)?(\d+)`, zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
34+
engine.OnMessage(zero.NewPattern().Text(`^查好感度`).At().AsRule(), zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
3535
Handle(func(ctx *zero.Ctx) {
36-
fiancee, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
36+
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
37+
fiancee, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
3738
uid := ctx.Event.UserID
3839
favor, err := 民政局.查好感度(uid, fiancee)
3940
if err != nil {
@@ -47,12 +48,12 @@ func init() {
4748
)
4849
})
4950
// 礼物系统
50-
engine.OnRegex(`^买礼物给\s?(\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]|(\d+))`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
51+
engine.OnMessage(zero.NewPattern().Text(`^买礼物给`).At().AsRule(), zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
5152
Handle(func(ctx *zero.Ctx) {
5253
gid := ctx.Event.GroupID
5354
uid := ctx.Event.UserID
54-
fiancee := ctx.State["regex_matched"].([]string)
55-
gay, _ := strconv.ParseInt(fiancee[2]+fiancee[3], 10, 64)
55+
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
56+
gay, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
5657
if gay == uid {
5758
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.At(uid), message.Text("你想给自己买什么礼物呢?")))
5859
return

plugin/qqwife/function.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ func init() {
9393
ctx.SendChain(message.Text("设置成功"))
9494
})
9595
// 单身技能
96-
engine.OnRegex(`^(娶|嫁)\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]`, zero.OnlyGroup, getdb, checkSingleDog).SetBlock(true).Limit(ctxext.LimitByUser).
96+
engine.OnMessage(zero.NewPattern().Text(`^(娶|嫁)`).At().AsRule(), zero.OnlyGroup, getdb, checkSingleDog).SetBlock(true).Limit(ctxext.LimitByUser).
9797
Handle(func(ctx *zero.Ctx) {
9898
gid := ctx.Event.GroupID
9999
uid := ctx.Event.UserID
100-
choice := ctx.State["regex_matched"].([]string)[1]
101-
fiancee, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
100+
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
101+
choice := patternParsed[0].Text()[0]
102+
fiancee, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
102103
// 写入CD
103104
err := 民政局.记录CD(gid, uid, "嫁娶")
104105
if err != nil {
@@ -167,12 +168,12 @@ func init() {
167168
)
168169
})
169170
// NTR技能
170-
engine.OnRegex(`^当(\[CQ:at,qq=(\d+)\]\s?|(\d+))的小三`, zero.OnlyGroup, getdb, checkMistress).SetBlock(true).Limit(ctxext.LimitByUser).
171+
engine.OnMessage(zero.NewPattern().Text(`^当`).At().Text(`的小三`).AsRule(), zero.OnlyGroup, getdb, checkMistress).SetBlock(true).Limit(ctxext.LimitByUser).
171172
Handle(func(ctx *zero.Ctx) {
172173
gid := ctx.Event.GroupID
173174
uid := ctx.Event.UserID
174-
fid := ctx.State["regex_matched"].([]string)
175-
fiancee, _ := strconv.ParseInt(fid[2]+fid[3], 10, 64)
175+
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
176+
fiancee, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
176177
// 写入CD
177178
err := 民政局.记录CD(gid, uid, "NTR")
178179
if err != nil {
@@ -253,12 +254,13 @@ func init() {
253254
)
254255
})
255256
// 做媒技能
256-
engine.OnRegex(`^做媒\s?\[CQ:at,qq=(\d+)\]\s?\[CQ:at,qq=(\d+)\]`, zero.OnlyGroup, zero.AdminPermission, getdb, checkMatchmaker).SetBlock(true).Limit(ctxext.LimitByUser).
257+
engine.OnMessage(zero.NewPattern().Text(`做媒`).At().At().AsRule(), zero.OnlyGroup, zero.AdminPermission, getdb, checkMatchmaker).SetBlock(true).Limit(ctxext.LimitByUser).
257258
Handle(func(ctx *zero.Ctx) {
258259
gid := ctx.Event.GroupID
259260
uid := ctx.Event.UserID
260-
gayOne, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
261-
gayZero, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
261+
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
262+
gayOne, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
263+
gayZero, _ := strconv.ParseInt(patternParsed[2].At(), 10, 64)
262264
// 写入CD
263265
err := 民政局.记录CD(gid, uid, "做媒")
264266
if err != nil {
@@ -416,7 +418,8 @@ func (sql *婚姻登记) 离婚休夫(gid, husband int64) error {
416418
func checkSingleDog(ctx *zero.Ctx) bool {
417419
gid := ctx.Event.GroupID
418420
uid := ctx.Event.UserID
419-
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
421+
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
422+
fiancee, err := strconv.ParseInt(patternParsed[1].At(), 10, 64)
420423
if err != nil {
421424
ctx.SendChain(message.Text("额,你的target好像不存在?"))
422425
return false
@@ -482,7 +485,8 @@ func checkSingleDog(ctx *zero.Ctx) bool {
482485
func checkMistress(ctx *zero.Ctx) bool {
483486
gid := ctx.Event.GroupID
484487
uid := ctx.Event.UserID
485-
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
488+
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
489+
fiancee, err := strconv.ParseInt(patternParsed[1].At(), 10, 64)
486490
if err != nil {
487491
ctx.SendChain(message.Text("额,你的target好像不存在?"))
488492
return false
@@ -578,12 +582,13 @@ func checkDivorce(ctx *zero.Ctx) bool {
578582
func checkMatchmaker(ctx *zero.Ctx) bool {
579583
gid := ctx.Event.GroupID
580584
uid := ctx.Event.UserID
581-
gayOne, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
585+
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
586+
gayOne, err := strconv.ParseInt(patternParsed[1].At(), 10, 64)
582587
if err != nil {
583588
ctx.SendChain(message.Text("额,攻方好像不存在?"))
584589
return false
585590
}
586-
gayZero, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
591+
gayZero, err := strconv.ParseInt(patternParsed[2].At(), 10, 64)
587592
if err != nil {
588593
ctx.SendChain(message.Text("额,受方好像不存在?"))
589594
return false

0 commit comments

Comments
 (0)