Skip to content

Commit

Permalink
feat(qqwife): some onregex -> pattern (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiang-Red authored Nov 9, 2024
1 parent 4ba0b36 commit 9e8ae43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
11 changes: 6 additions & 5 deletions plugin/qqwife/favorSystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ type favorability struct {

func init() {
// 好感度系统
engine.OnRegex(`^查好感度\s*(\[CQ:at,qq=)?(\d+)`, zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
engine.OnMessage(zero.NewPattern().Text(`^查好感度`).At().AsRule(), zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
fiancee, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
fiancee, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
uid := ctx.Event.UserID
favor, err := 民政局.查好感度(uid, fiancee)
if err != nil {
Expand All @@ -47,12 +48,12 @@ func init() {
)
})
// 礼物系统
engine.OnRegex(`^买礼物给\s?(\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]|(\d+))`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
engine.OnMessage(zero.NewPattern().Text(`^买礼物给`).At().AsRule(), zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
fiancee := ctx.State["regex_matched"].([]string)
gay, _ := strconv.ParseInt(fiancee[2]+fiancee[3], 10, 64)
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
gay, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
if gay == uid {
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.At(uid), message.Text("你想给自己买什么礼物呢?")))
return
Expand Down
31 changes: 18 additions & 13 deletions plugin/qqwife/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ func init() {
ctx.SendChain(message.Text("设置成功"))
})
// 单身技能
engine.OnRegex(`^(娶|嫁)\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]`, zero.OnlyGroup, getdb, checkSingleDog).SetBlock(true).Limit(ctxext.LimitByUser).
engine.OnMessage(zero.NewPattern().Text(`^(娶|嫁)`).At().AsRule(), zero.OnlyGroup, getdb, checkSingleDog).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
choice := ctx.State["regex_matched"].([]string)[1]
fiancee, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
choice := patternParsed[0].Text()[0]
fiancee, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
// 写入CD
err := 民政局.记录CD(gid, uid, "嫁娶")
if err != nil {
Expand Down Expand Up @@ -167,12 +168,12 @@ func init() {
)
})
// NTR技能
engine.OnRegex(`^当(\[CQ:at,qq=(\d+)\]\s?|(\d+))的小三`, zero.OnlyGroup, getdb, checkMistress).SetBlock(true).Limit(ctxext.LimitByUser).
engine.OnMessage(zero.NewPattern().Text(`^当`).At().Text(`的小三`).AsRule(), zero.OnlyGroup, getdb, checkMistress).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
fid := ctx.State["regex_matched"].([]string)
fiancee, _ := strconv.ParseInt(fid[2]+fid[3], 10, 64)
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
fiancee, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
// 写入CD
err := 民政局.记录CD(gid, uid, "NTR")
if err != nil {
Expand Down Expand Up @@ -253,12 +254,13 @@ func init() {
)
})
// 做媒技能
engine.OnRegex(`^做媒\s?\[CQ:at,qq=(\d+)\]\s?\[CQ:at,qq=(\d+)\]`, zero.OnlyGroup, zero.AdminPermission, getdb, checkMatchmaker).SetBlock(true).Limit(ctxext.LimitByUser).
engine.OnMessage(zero.NewPattern().Text(`做媒`).At().At().AsRule(), zero.OnlyGroup, zero.AdminPermission, getdb, checkMatchmaker).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
gayOne, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
gayZero, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
gayOne, _ := strconv.ParseInt(patternParsed[1].At(), 10, 64)
gayZero, _ := strconv.ParseInt(patternParsed[2].At(), 10, 64)
// 写入CD
err := 民政局.记录CD(gid, uid, "做媒")
if err != nil {
Expand Down Expand Up @@ -416,7 +418,8 @@ func (sql *婚姻登记) 离婚休夫(gid, husband int64) error {
func checkSingleDog(ctx *zero.Ctx) bool {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
fiancee, err := strconv.ParseInt(patternParsed[1].At(), 10, 64)
if err != nil {
ctx.SendChain(message.Text("额,你的target好像不存在?"))
return false
Expand Down Expand Up @@ -482,7 +485,8 @@ func checkSingleDog(ctx *zero.Ctx) bool {
func checkMistress(ctx *zero.Ctx) bool {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
fiancee, err := strconv.ParseInt(patternParsed[1].At(), 10, 64)
if err != nil {
ctx.SendChain(message.Text("额,你的target好像不存在?"))
return false
Expand Down Expand Up @@ -578,12 +582,13 @@ func checkDivorce(ctx *zero.Ctx) bool {
func checkMatchmaker(ctx *zero.Ctx) bool {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
gayOne, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
patternParsed := ctx.State[zero.KeyPattern].([]zero.PatternParsed)
gayOne, err := strconv.ParseInt(patternParsed[1].At(), 10, 64)
if err != nil {
ctx.SendChain(message.Text("额,攻方好像不存在?"))
return false
}
gayZero, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
gayZero, err := strconv.ParseInt(patternParsed[2].At(), 10, 64)
if err != nil {
ctx.SendChain(message.Text("额,受方好像不存在?"))
return false
Expand Down

0 comments on commit 9e8ae43

Please sign in to comment.