From cbb16963e4de0d527b41aa31cb5c3c31be6d175b Mon Sep 17 00:00:00 2001 From: cdle <798731886@qq.com> Date: Fri, 8 Oct 2021 11:42:15 +0800 Subject: [PATCH] update --- .gitignore | 3 ++- core/push.go | 45 +++++++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 954d93c..d7b071c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ jd_* data dwz replies -qinglongs \ No newline at end of file +qinglongs +sets.conf \ No newline at end of file diff --git a/core/push.go b/core/push.go index d2d0f77..127c934 100644 --- a/core/push.go +++ b/core/push.go @@ -1,6 +1,12 @@ package core -import "regexp" +import ( + "regexp" + "strings" + "sync" + + "github.com/beego/beego/v2/adapter/httplib" +) var Pushs = map[string]func(int, string){} var GroupPushs = map[string]func(int, int, string){} @@ -30,19 +36,34 @@ func (ct *Chat) Push(content interface{}) { } } +var notLock sync.Locker +var msgs = map[string]string{} + func NotifyMasters(content string) { - if sillyGirl.GetBool("ignore_notify", false) == true { - return - } - for _, class := range []string{"tg", "qq"} { - notify := Bucket(class).Get("notifiers") - if notify == "" { - notify = Bucket(class).Get("masters") + go func() { + content = strings.Trim(content, " ") + notLock.Lock() + defer notLock.Unlock() + if _, ok := msgs[content]; ok { + return } - for _, v := range regexp.MustCompile(`(\d+)`).FindAllStringSubmatch(notify, -1) { - if push, ok := Pushs[class]; ok { - push(Int(v[1]), content) + msgs[content] = "" + if sillyGirl.GetBool("ignore_notify", false) == true { + return + } + if token := sillyGirl.Get("pushplus"); token != "" { + httplib.Get("http://www.pushplus.plus/send?token=" + token + "&title=0101010&content=" + content + "&template=html") + } + for _, class := range []string{"tg", "qq"} { + notify := Bucket(class).Get("notifiers") + if notify == "" { + notify = Bucket(class).Get("masters") + } + for _, v := range regexp.MustCompile(`(\d+)`).FindAllStringSubmatch(notify, -1) { + if push, ok := Pushs[class]; ok { + push(Int(v[1]), content) + } } } - } + }() }