From fd8cab26e0afd8e3669a13ae39e4f0ff0b804291 Mon Sep 17 00:00:00 2001 From: cdle <798731886@qq.com> Date: Thu, 14 Oct 2021 09:45:54 +0800 Subject: [PATCH] update --- core/im.go | 2 +- core/test.go | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/im.go b/core/im.go index 859454b..0e40f5b 100644 --- a/core/im.go +++ b/core/im.go @@ -248,7 +248,7 @@ func (_ *BaseSender) Await(sender Sender, callback func(Sender) interface{}, par return } if c.Pattern == "" { - return + c.Pattern = `[\s\S]*` } c.Chan = make(chan interface{}, 1) c.Result = make(chan interface{}, 1) diff --git a/core/test.go b/core/test.go index 56bb9be..b13b807 100644 --- a/core/test.go +++ b/core/test.go @@ -269,14 +269,21 @@ Alias=sillyGirl.service` Rules: []string{"raw ^成语接龙$"}, Handle: func(s Sender) interface{} { id := fmt.Sprintf("%v", s.GetUserID()) + start: data, err := httplib.Get("http://hm.suol.cc/API/cyjl.php?id=" + id + "&msg=开始成语接龙").String() if err != nil { s.Reply(err) } s.Reply(data) stop := false + goon := false + win := false if strings.Contains(data, "你赢") { stop = true + win = true + } + if strings.Contains(data, "我赢") { + stop = true } for { if stop == true { @@ -290,7 +297,7 @@ Alias=sillyGirl.service` } if strings.Contains(ct, "认输") { stop = true - return "菜*,见一次虐一次!" + return nil } cy := regexp.MustCompile("^[一-龥]+$").FindString(ct) if cy == "" { @@ -308,15 +315,32 @@ Alias=sillyGirl.service` } if strings.Contains(data, "你赢") { stop = true + win = true } else if strings.Contains(data, "恭喜") { } else { data += "玩不过就认输呗。" } return data - }, `[\s\S]*`, time.Duration(time.Second*300)) + }) } + s.Reply("还玩吗?[Y/n]") + s.Await(s, func(s2 Sender) interface{} { + msg := s2.GetContent() + if strings.ToLower(msg) == "Y" || strings.ToLower(msg) == "yes" { + goon = true + } + return nil + }) + if goon { + goto start + } + if !win { + s.Reply("菜*,见一次虐一次!") + } else { + s.Reply("大爷下次再来玩啊~") + } return nil }, },