From 3fbb34bb834e18b523250aeb7553123a62847134 Mon Sep 17 00:00:00 2001 From: himawari <1156544355@qq.com> Date: Sun, 8 May 2022 18:34:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E7=BD=91?= =?UTF-8?q?=E6=98=93=E7=82=B9=E6=AD=8C=EF=BC=8Cqq=E7=82=B9=E6=AD=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/epidemic/epidemic.go | 4 +- plugin/music/selecter.go | 83 ++++------------------------------- plugin/shadiao/caihongpi.go | 21 --------- plugin/shadiao/dujitang.go | 21 --------- plugin/shadiao/pengyouquan.go | 21 --------- plugin/shadiao/shadiao.go | 27 ++++++++++-- 6 files changed, 33 insertions(+), 144 deletions(-) delete mode 100644 plugin/shadiao/caihongpi.go delete mode 100644 plugin/shadiao/dujitang.go delete mode 100644 plugin/shadiao/pengyouquan.go diff --git a/plugin/epidemic/epidemic.go b/plugin/epidemic/epidemic.go index f9da776a82..85667e84de 100644 --- a/plugin/epidemic/epidemic.go +++ b/plugin/epidemic/epidemic.go @@ -34,8 +34,8 @@ type epidemic struct { type area struct { Name string `json:"name"` Today struct { - Confirm int `json:"confirm"` - Wzzadd int `json:"wzz_add"` + Confirm int `json:"confirm"` + Wzzadd interface{} `json:"wzz_add"` } `json:"today"` Total struct { NowConfirm int `json:"nowConfirm"` diff --git a/plugin/music/selecter.go b/plugin/music/selecter.go index 3e1819fbb8..87320e160e 100644 --- a/plugin/music/selecter.go +++ b/plugin/music/selecter.go @@ -5,6 +5,7 @@ import ( "crypto/md5" "encoding/hex" "fmt" + "github.com/FloatTech/zbputils/web" "io" "net/http" "net/url" @@ -135,71 +136,17 @@ func kugou(keyword string) message.MessageSegment { // cloud163 返回网易云音乐卡片 func cloud163(keyword string) message.MessageSegment { - headers := http.Header{ - "Content-Type": []string{"application/x-www-form-urlencoded"}, - "User-Agent": []string{"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"}, - } - data := url.Values{ - "keywords": []string{keyword}, - } - // 通过API 搜索音乐信息 第一首 - // 返回音乐卡片 - return message.Music("163", gjson.ParseBytes(netPost("https://nemapi.windis.xyz/search", data, headers)).Get("result.songs.0.id").Int()) + requestURL := "https://autumnfish.cn/search?keywords=" + url.QueryEscape(keyword) + data, _ := web.GetData(requestURL) + return message.Music("163", gjson.ParseBytes(data).Get("result.songs.0.id").Int()) } // qqmusic 返回QQ音乐卡片 func qqmusic(keyword string) message.MessageSegment { - // 搜索音乐信息 第一首歌 - h1 := http.Header{ - "User-Agent": []string{"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"}, - } - search, _ := url.Parse("https://c.y.qq.com/soso/fcgi-bin/client_search_cp") - search.RawQuery = url.Values{ - "w": []string{keyword}, - }.Encode() - res := netGet(search.String(), h1) - info := gjson.ParseBytes(res[9 : len(res)-1]).Get("data.song.list.0") - // 获得音乐直链 - h2 := http.Header{ - "User-Agent": []string{"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"}, - "referer": []string{"http://y.qq.com"}, - } - music, _ := url.Parse("https://u.y.qq.com/cgi-bin/musicu.fcg") - music.RawQuery = url.Values{ - "data": []string{`{"req": {"module": "CDN.SrfCdnDispatchServer", "method": "GetCdnDispatch", "param": {"guid": "3982823384", "calltype": 0, "userip": ""}}, "req_0": {"module": "vkey.GetVkeyServer", "method": "CgiGetVkey", "param": {"guid": "3982823384", "songmid": ["` + info.Get("songmid").Str + `"], "songtype": [0], "uin": "0", "loginflag": 1, "platform": "20"}}, "comm": {"uin": 0, "format": "json", "ct": 24, "cv": 0}}`}, - }.Encode() - audio := gjson.ParseBytes(netGet(music.String(), h2)) - // 获得音乐封面 - image := "https://y.gtimg.cn/music/photo_new/" + - find( - `photo_new\u002F`, - "?max_age", - string( - netGet("https://y.qq.com/n/yqq/song/"+info.Get("songmid").Str+".html", nil), - ), - ) - // 返回音乐卡片 - return message.CustomMusic( - "https://y.qq.com/n/yqq/song/"+info.Get("songmid").Str+".html", - "https://isure.stream.qqmusic.qq.com/"+audio.Get("req_0.data.midurlinfo.0.purl").Str, - info.Get("songname").Str, - ).Add("content", info.Get("singer.0.name").Str).Add("image", image) -} - -// find 返回 pre 到 suf 之间的文本 -func find(pre string, suf string, str string) string { - n := strings.Index(str, pre) - if n == -1 { - n = 0 - } else { - n += len(pre) - } - str = str[n:] - m := strings.Index(str, suf) - if m == -1 { - m = len(str) - } - return str[:m] + requestURL := "https://c.y.qq.com/soso/fcgi-bin/client_search_cp?w=" + url.QueryEscape(keyword) + data, _ := web.RequestDataWith(web.NewDefaultClient(), requestURL, "GET", "", web.RandUA()) + info := gjson.ParseBytes(data[9 : len(data)-1]).Get("data.song.list.0") + return message.Music("qq", info.Get("songid").Int()) } // md5str 返回字符串 MD5 @@ -223,17 +170,3 @@ func netGet(url string, header http.Header) []byte { result, _ := io.ReadAll(res.Body) return result } - -// netPost 返回请求数据 -func netPost(url string, data url.Values, header http.Header) []byte { - client := &http.Client{} - request, _ := http.NewRequest("POST", url, strings.NewReader(data.Encode())) - request.Header = header - res, err := client.Do(request) - if err != nil { - return nil - } - defer res.Body.Close() - result, _ := io.ReadAll(res.Body) - return result -} diff --git a/plugin/shadiao/caihongpi.go b/plugin/shadiao/caihongpi.go deleted file mode 100644 index 4e04a80a93..0000000000 --- a/plugin/shadiao/caihongpi.go +++ /dev/null @@ -1,21 +0,0 @@ -package shadiao - -import ( - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" - "github.com/wdvxdr1123/ZeroBot/utils/helper" - - "github.com/FloatTech/zbputils/ctxext" - "github.com/FloatTech/zbputils/web" -) - -func init() { - engine.OnFullMatch("哄我").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.RequestDataWith(web.NewDefaultClient(), chpURL, "GET", chpReferer, ua) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } - ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(helper.BytesToString(data))) - }) -} diff --git a/plugin/shadiao/dujitang.go b/plugin/shadiao/dujitang.go deleted file mode 100644 index 0ffe1fc6a1..0000000000 --- a/plugin/shadiao/dujitang.go +++ /dev/null @@ -1,21 +0,0 @@ -package shadiao - -import ( - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" - "github.com/wdvxdr1123/ZeroBot/utils/helper" - - "github.com/FloatTech/zbputils/ctxext" - "github.com/FloatTech/zbputils/web" -) - -func init() { - engine.OnFullMatch("来碗毒鸡汤").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.RequestDataWith(web.NewDefaultClient(), duURL, "GET", duReferer, ua) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } - ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(helper.BytesToString(data))) - }) -} diff --git a/plugin/shadiao/pengyouquan.go b/plugin/shadiao/pengyouquan.go deleted file mode 100644 index 21fabde6c3..0000000000 --- a/plugin/shadiao/pengyouquan.go +++ /dev/null @@ -1,21 +0,0 @@ -package shadiao - -import ( - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" - "github.com/wdvxdr1123/ZeroBot/utils/helper" - - "github.com/FloatTech/zbputils/ctxext" - "github.com/FloatTech/zbputils/web" -) - -func init() { - engine.OnFullMatch("发个朋友圈").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.RequestDataWith(web.NewDefaultClient(), pyqURL, "GET", pyqReferer, ua) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } - ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(helper.BytesToString(data))) - }) -} diff --git a/plugin/shadiao/shadiao.go b/plugin/shadiao/shadiao.go index 85b660534d..93b9539fd8 100644 --- a/plugin/shadiao/shadiao.go +++ b/plugin/shadiao/shadiao.go @@ -2,20 +2,24 @@ package shadiao import ( + "fmt" control "github.com/FloatTech/zbputils/control" + "github.com/FloatTech/zbputils/ctxext" + "github.com/FloatTech/zbputils/web" + "github.com/tidwall/gjson" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" ) const ( - chpURL = "https://chp.shadiao.app/chp" + chpURL = "https://api.shadiao.app/chp" duURL = "https://api.shadiao.app/du" pyqURL = "https://api.shadiao.app/pyq" yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi" chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0" ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1" ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" - chpReferer = "https://chp.shadiao.app/" - duReferer = "https://du.shadiao.app/" - pyqReferer = "https://pyq.shadiao.app/" + sdReferer = "https://api.shadiao.app/" yduanziReferer = "http://www.yduanzi.com/?utm_source=shadiao.app" loveliveReferer = "https://lovelive.tools/" ) @@ -26,4 +30,19 @@ var ( Help: "沙雕app\n" + "- 哄我\n- 渣我\n- 来碗绿茶\n- 发个朋友圈\n- 来碗毒鸡汤\n- 讲个段子", }) + sdMap = map[string]string{"哄我": chpURL, "来碗毒鸡汤": duURL, "发个朋友圈": pyqURL} ) + +func init() { + engine.OnFullMatchGroup([]string{"哄我", "来碗毒鸡汤", "发个朋友圈"}).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { + fmt.Println(ctx.State["matched"].(string)) + requestURL := sdMap[ctx.State["matched"].(string)] + data, err := web.RequestDataWith(web.NewDefaultClient(), requestURL, "GET", sdReferer, ua) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(gjson.GetBytes(data, "data.text").String())) + + }) +} From e63b08f2d1f66fb36d2f11d86405d563ee4f755b Mon Sep 17 00:00:00 2001 From: himawari <1156544355@qq.com> Date: Sun, 8 May 2022 18:55:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=9A=A8=20=E9=94=99=E8=AF=AF=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/music/selecter.go | 26 ++++++++++++++++++-------- plugin/shadiao/shadiao.go | 2 -- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/plugin/music/selecter.go b/plugin/music/selecter.go index 87320e160e..af8a6dc424 100644 --- a/plugin/music/selecter.go +++ b/plugin/music/selecter.go @@ -36,9 +36,9 @@ func init() { case "酷狗": ctx.SendChain(kugou(ctx.State["regex_matched"].([]string)[2])) case "网易": - ctx.SendChain(cloud163(ctx.State["regex_matched"].([]string)[2])) + ctx.SendChain(cloud163(ctx, ctx.State["regex_matched"].([]string)[2])) default: // 默认 QQ音乐 - ctx.SendChain(qqmusic(ctx.State["regex_matched"].([]string)[2])) + ctx.SendChain(qqmusic(ctx, ctx.State["regex_matched"].([]string)[2])) } }) } @@ -135,18 +135,28 @@ func kugou(keyword string) message.MessageSegment { } // cloud163 返回网易云音乐卡片 -func cloud163(keyword string) message.MessageSegment { +func cloud163(ctx *zero.Ctx, keyword string) (msg message.MessageSegment) { requestURL := "https://autumnfish.cn/search?keywords=" + url.QueryEscape(keyword) - data, _ := web.GetData(requestURL) - return message.Music("163", gjson.ParseBytes(data).Get("result.songs.0.id").Int()) + data, err := web.GetData(requestURL) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + msg = message.Music("163", gjson.ParseBytes(data).Get("result.songs.0.id").Int()) + return } // qqmusic 返回QQ音乐卡片 -func qqmusic(keyword string) message.MessageSegment { +func qqmusic(ctx *zero.Ctx, keyword string) (msg message.MessageSegment) { requestURL := "https://c.y.qq.com/soso/fcgi-bin/client_search_cp?w=" + url.QueryEscape(keyword) - data, _ := web.RequestDataWith(web.NewDefaultClient(), requestURL, "GET", "", web.RandUA()) + data, err := web.RequestDataWith(web.NewDefaultClient(), requestURL, "GET", "", web.RandUA()) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } info := gjson.ParseBytes(data[9 : len(data)-1]).Get("data.song.list.0") - return message.Music("qq", info.Get("songid").Int()) + msg = message.Music("qq", info.Get("songid").Int()) + return } // md5str 返回字符串 MD5 diff --git a/plugin/shadiao/shadiao.go b/plugin/shadiao/shadiao.go index 93b9539fd8..287546b7b0 100644 --- a/plugin/shadiao/shadiao.go +++ b/plugin/shadiao/shadiao.go @@ -2,7 +2,6 @@ package shadiao import ( - "fmt" control "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" "github.com/FloatTech/zbputils/web" @@ -35,7 +34,6 @@ var ( func init() { engine.OnFullMatchGroup([]string{"哄我", "来碗毒鸡汤", "发个朋友圈"}).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - fmt.Println(ctx.State["matched"].(string)) requestURL := sdMap[ctx.State["matched"].(string)] data, err := web.RequestDataWith(web.NewDefaultClient(), requestURL, "GET", sdReferer, ua) if err != nil { From 1f7bebbea0301720a9beb1d688c958ec960b383a Mon Sep 17 00:00:00 2001 From: himawari <1156544355@qq.com> Date: Sun, 8 May 2022 22:10:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=9A=A8=20=E9=94=99=E8=AF=AF=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/music/selecter.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin/music/selecter.go b/plugin/music/selecter.go index af8a6dc424..196c71c99d 100644 --- a/plugin/music/selecter.go +++ b/plugin/music/selecter.go @@ -36,9 +36,9 @@ func init() { case "酷狗": ctx.SendChain(kugou(ctx.State["regex_matched"].([]string)[2])) case "网易": - ctx.SendChain(cloud163(ctx, ctx.State["regex_matched"].([]string)[2])) + ctx.SendChain(cloud163(ctx.State["regex_matched"].([]string)[2])) default: // 默认 QQ音乐 - ctx.SendChain(qqmusic(ctx, ctx.State["regex_matched"].([]string)[2])) + ctx.SendChain(qqmusic(ctx.State["regex_matched"].([]string)[2])) } }) } @@ -135,11 +135,11 @@ func kugou(keyword string) message.MessageSegment { } // cloud163 返回网易云音乐卡片 -func cloud163(ctx *zero.Ctx, keyword string) (msg message.MessageSegment) { +func cloud163(keyword string) (msg message.MessageSegment) { requestURL := "https://autumnfish.cn/search?keywords=" + url.QueryEscape(keyword) data, err := web.GetData(requestURL) if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) + msg = message.Text("ERROR:", err) return } msg = message.Music("163", gjson.ParseBytes(data).Get("result.songs.0.id").Int()) @@ -147,11 +147,11 @@ func cloud163(ctx *zero.Ctx, keyword string) (msg message.MessageSegment) { } // qqmusic 返回QQ音乐卡片 -func qqmusic(ctx *zero.Ctx, keyword string) (msg message.MessageSegment) { +func qqmusic(keyword string) (msg message.MessageSegment) { requestURL := "https://c.y.qq.com/soso/fcgi-bin/client_search_cp?w=" + url.QueryEscape(keyword) data, err := web.RequestDataWith(web.NewDefaultClient(), requestURL, "GET", "", web.RandUA()) if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) + msg = message.Text("ERROR:", err) return } info := gjson.ParseBytes(data[9 : len(data)-1]).Get("data.song.list.0")