diff --git a/core/test.go b/core/test.go index a979034..715dffc 100644 --- a/core/test.go +++ b/core/test.go @@ -6,8 +6,11 @@ import ( "io/ioutil" "os" "os/exec" + "regexp" "strings" "time" + + "github.com/beego/beego/v2/adapter/httplib" ) func init() { @@ -265,6 +268,32 @@ Alias=sillyGirl.service` } }, }, + { + Rules: []string{"raw ^成语接龙$"}, + Handle: func(s Sender) interface{} { + id := fmt.Sprintf("%v", s.GetChatID()) + data, err := httplib.Get("http://hm.suol.cc/API/cyjl.php?id=" + id + "&msg=开始成语接龙").String() + if err != nil { + s.Reply(err) + } + s.Reply(data) + for { + s.Await(s, func(s1 string, s2 Sender, _ error) interface{} { + cy := regexp.MustCompile("^[一-龥]{4}$").FindString(s1) + if cy == "" { + s2.Disappear(time.Millisecond * 500) + return "请认真接龙,一站到底!。" + } + data, err := httplib.Get("http://hm.suol.cc/API/cyjl.php?id=" + id + "&msg=我接" + cy).String() + if err != nil { + s2.Reply(err) + return nil + } + return data + }, `[\s\S]*`, time.Duration(time.Second*300)) + } + }, + }, }) }