From e2a1b4dd60106f448f5e128e2eaeef63a3f741bd Mon Sep 17 00:00:00 2001 From: cdle <798731886@qq.com> Date: Fri, 15 Oct 2021 09:05:51 +0800 Subject: [PATCH] update --- core/function.go | 39 ++++++++++++++++++++++++++++++++++++--- core/im.go | 11 +++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/core/function.go b/core/function.go index 67660ae..0e36797 100644 --- a/core/function.go +++ b/core/function.go @@ -2,6 +2,7 @@ package core import ( "fmt" + "net/url" "os" "regexp" "strings" @@ -80,15 +81,47 @@ func AddCommand(prefix string, cmds []Function) { func handleMessage(sender Sender) { defer sender.Finish() - key := fmt.Sprintf("u=%v&c=%v&i=%v", sender.GetUserID(), sender.GetChatID(), sender.GetImType()) - if v, ok := waits.Load(key); ok { + u, g, i := fmt.Sprint(sender.GetUserID()), fmt.Sprint(sender.GetChatID()), fmt.Sprint(sender.GetImType()) + con := true + mtd := false + waits.Range(func(k, v interface{}) bool { c := v.(*Carry) + vs, _ := url.ParseQuery(k.(string)) + userID := vs.Get("u") + chatID := vs.Get("c") + imType := vs.Get("i") + forGroup := vs.Get("f") + if imType != i { + return true + } + if chatID != g { + return true + } + if userID != u && forGroup == "" { + return true + } if m := regexp.MustCompile(c.Pattern).FindString(sender.GetContent()); m != "" { + mtd = true c.Chan <- sender sender.Reply(<-c.Result) - return + if !sender.IsContinue() { + con = false + return false + } } + return true + }) + if mtd && !con { + return } + // if v, ok := waits.Load(key); ok { + // c := v.(*Carry) + // if m := regexp.MustCompile(c.Pattern).FindString(sender.GetContent()); m != "" { + // c.Chan <- sender + // sender.Reply(<-c.Result) + // return + // } + // } for _, function := range functions { for _, rule := range function.Rules { var matched bool diff --git a/core/im.go b/core/im.go index 0e40f5b..02a116c 100644 --- a/core/im.go +++ b/core/im.go @@ -224,10 +224,15 @@ type Carry struct { Sender Sender } +type forGroup string + +var ForGroup forGroup + func (_ *BaseSender) Await(sender Sender, callback func(Sender) interface{}, params ...interface{}) { c := &Carry{} timeout := time.Second * 20 var handleErr func(error) + var fg *forGroup for _, param := range params { switch param.(type) { case string: @@ -242,6 +247,9 @@ func (_ *BaseSender) Await(sender Sender, callback func(Sender) interface{}, par case func(error): handleErr = param.(func(error)) + case forGroup: + a := param.(forGroup) + fg = &a } } if callback == nil { @@ -253,6 +261,9 @@ func (_ *BaseSender) Await(sender Sender, callback func(Sender) interface{}, par c.Chan = make(chan interface{}, 1) c.Result = make(chan interface{}, 1) key := fmt.Sprintf("u=%v&c=%v&i=%v", sender.GetUserID(), sender.GetChatID(), sender.GetImType()) + if fg != nil { + key += fmt.Sprintf("&t=%v&f=true", time.Now().Unix()) + } if oc, ok := waits.LoadOrStore(key, c); ok { oc.(*Carry).Chan <- InterruptError }