diff --git a/go.mod b/go.mod index 8cacb408b5..837e1ffda3 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/FloatTech/ZeroBot-Plugin go 1.17 require ( - github.com/FloatTech/AnimeAPI v1.3.0 + github.com/FloatTech/AnimeAPI v1.3.1-0.20220227112758-da30b39dd7a7 github.com/FloatTech/sqlite v0.2.0 - github.com/FloatTech/zbputils v1.3.0 + github.com/FloatTech/zbputils v1.3.1-0.20220227112438-2ccf42cc85d3 github.com/antchfx/htmlquery v1.2.4 github.com/corona10/goimagehash v1.0.3 github.com/fogleman/gg v1.3.0 diff --git a/go.sum b/go.sum index 8e397396dd..6c0352254c 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,10 @@ -github.com/FloatTech/AnimeAPI v1.3.0 h1:99WNHJ/VqqdzN8q3ul0oY4j5FxT+wp8fnvBtsN6qpa4= -github.com/FloatTech/AnimeAPI v1.3.0/go.mod h1:uEzRyhIgYA5/pcBhlvHOfGiTvLH1qZkICxnVGU+4b/8= +github.com/FloatTech/AnimeAPI v1.3.1-0.20220227112758-da30b39dd7a7 h1:JOmelUrxBef/Sg/15PgkBC3IV4BpORQwiSWfqV1nCD0= +github.com/FloatTech/AnimeAPI v1.3.1-0.20220227112758-da30b39dd7a7/go.mod h1:AuFa+9NWdJujJc2PvCoO2NqLOwwwFXKy69X0zexsZS0= github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ= github.com/FloatTech/sqlite v0.2.0 h1:x3uls/hExXH1+bbaNLkvilce6ATtWlDx4IqoxBW/bv8= github.com/FloatTech/sqlite v0.2.0/go.mod h1:xIDWIvpOFl8AXmZm0FC8t3PZjiR6ZutytCpBv2EWCns= -github.com/FloatTech/zbputils v1.3.0 h1:gCJbDpKdMu1bavA8FGr2kmMFgeL8Dcsj9BBOkYiMprI= -github.com/FloatTech/zbputils v1.3.0/go.mod h1:NXv73hWyC4Q4S4wg01DEwLzznSHSmde0o03PnsS1DtY= +github.com/FloatTech/zbputils v1.3.1-0.20220227112438-2ccf42cc85d3 h1:BA9mbIE2D2hhZnGaFjgIbiUrwG4h6VjVYf4UoDnBVn8= +github.com/FloatTech/zbputils v1.3.1-0.20220227112438-2ccf42cc85d3/go.mod h1:NXv73hWyC4Q4S4wg01DEwLzznSHSmde0o03PnsS1DtY= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0= github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0= diff --git a/plugin/bilibili_push/bilibili_push.go b/plugin/bilibili_push/bilibili_push.go index cca2750c21..8651b98b36 100644 --- a/plugin/bilibili_push/bilibili_push.go +++ b/plugin/bilibili_push/bilibili_push.go @@ -232,7 +232,7 @@ func bilibiliPushDaily() { } func checkBuid(buid int64) (status int, name string) { - data, err := web.ReqWith(fmt.Sprintf(infoURL, buid), "GET", referer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), fmt.Sprintf(infoURL, buid), "GET", referer, ua) if err != nil { log.Errorln("[bilibilipush]:", err) } @@ -290,7 +290,7 @@ func unsubscribeLive(buid, groupid int64) (err error) { } func getUserDynamicCard(buid int64) (cardList []gjson.Result) { - data, err := web.ReqWith(fmt.Sprintf(userDynamicURL, buid), "GET", referer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), fmt.Sprintf(userDynamicURL, buid), "GET", referer, ua) if err != nil { log.Errorln("[bilibilipush]:", err) } diff --git a/plugin/coser/coser.go b/plugin/coser/coser.go index 1db8a5bccf..c491708e9b 100644 --- a/plugin/coser/coser.go +++ b/plugin/coser/coser.go @@ -28,7 +28,7 @@ func init() { }).ApplySingle(ctxext.DefaultSingle).OnFullMatch("coser", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByGroup). Handle(func(ctx *zero.Ctx) { ctx.SendChain(message.Text("少女祈祷中......")) - data, err := web.ReqWith(coserURL, "GET", "", ua) + data, err := web.GetDataWith(web.NewDefaultClient(), coserURL, "GET", "", ua) if err != nil { log.Println("err为:", err) } diff --git a/plugin/hs/run.go b/plugin/hs/run.go index cd430f8c6d..75163e5c0a 100644 --- a/plugin/hs/run.go +++ b/plugin/hs/run.go @@ -66,7 +66,7 @@ func init() { cid := gjson.Get(g, `list.`+strconv.Itoa(i)+`.CardID`).String() cachefile := cachedir + cid if file.IsNotExist(cachefile) { - data, err := web.ReqWith( + data, err := web.GetDataWith(web.NewDefaultClient(), `https://res.fbigame.com/hs/v13/`+cid+`.png?auth_key=`+ gjson.Get(g, `list.`+strconv.Itoa(i)+`.auth_key`).String(), reqconf[0], reqconf[1], reqconf[2]) @@ -105,10 +105,10 @@ func init() { } func sh(s string) string { - data, err := web.ReqWith("https://hs.fbigame.com", reqconf[0], reqconf[1], reqconf[2]) + data, err := web.GetDataWith(web.NewDefaultClient(), "https://hs.fbigame.com", reqconf[0], reqconf[1], reqconf[2]) if err == nil { url := hs + para + "&hash=" + strings.SplitN(strings.SplitN(helper.BytesToString(data), `var hash = "`, 2)[1], `"`, 2)[0] + "&search=" + s - r, err := web.ReqWith(url, reqconf[0], reqconf[1], reqconf[2]) + r, err := web.GetDataWith(web.NewDefaultClient(), url, reqconf[0], reqconf[1], reqconf[2]) if err == nil { return helper.BytesToString(r) } @@ -117,10 +117,10 @@ func sh(s string) string { } func kz(s string) string { - data, err := web.ReqWith("https://hs.fbigame.com", reqconf[0], reqconf[1], reqconf[2]) + data, err := web.GetDataWith(web.NewDefaultClient(), "https://hs.fbigame.com", reqconf[0], reqconf[1], reqconf[2]) if err == nil { url := hs + para + "mod=general_deck_image&deck_code=" + s + "&deck_text=&hash=" + strings.SplitN(strings.SplitN(helper.BytesToString(data), `var hash = "`, 2)[1], `"`, 2)[0] + "&search=" + s - r, err := web.ReqWith(url, reqconf[0], reqconf[1], reqconf[2]) + r, err := web.GetDataWith(web.NewDefaultClient(), url, reqconf[0], reqconf[1], reqconf[2]) if err == nil { return "base64://" + gjson.Get(helper.BytesToString(r), "img").String() } diff --git a/plugin/image_finder/keyword.go b/plugin/image_finder/keyword.go index ff42aaa8d8..6871d09029 100644 --- a/plugin/image_finder/keyword.go +++ b/plugin/image_finder/keyword.go @@ -70,7 +70,7 @@ func init() { // soutuapi 请求api func soutuapi(keyword string) (r resultjson, err error) { url := "https://api.pixivel.moe/v2/pixiv/illust/search/" + keyword + "?page=0" - data, err := web.ReqWith(url, "GET", "https://pixivel.moe/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36") + data, err := web.GetDataWith(web.NewTLS12Client(), url, "GET", "https://pixivel.moe/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36") if err != nil { return } diff --git a/plugin/score/sign_in.go b/plugin/score/sign_in.go index e2c3d5dc96..b062b3d896 100644 --- a/plugin/score/sign_in.go +++ b/plugin/score/sign_in.go @@ -204,12 +204,12 @@ func getLevel(count int) int { func initPic(picFile string) { if file.IsNotExist(picFile) { - data, err := web.ReqWith(backgroundURL, "GET", referer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), backgroundURL, "GET", referer, ua) if err != nil { log.Errorln("[score]", err) } picURL := gjson.Get(string(data), "pic").String() - data, err = web.ReqWith(picURL, "GET", "", ua) + data, err = web.GetDataWith(web.NewDefaultClient(), picURL, "GET", "", ua) if err != nil { log.Errorln("[score]", err) } diff --git a/plugin/shadiao/caihongpi.go b/plugin/shadiao/caihongpi.go index 73b89a1815..af1e32ade2 100644 --- a/plugin/shadiao/caihongpi.go +++ b/plugin/shadiao/caihongpi.go @@ -11,7 +11,7 @@ import ( func init() { engine.OnFullMatch("哄我").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.ReqWith(chpURL, "GET", chpReferer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), chpURL, "GET", chpReferer, ua) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return diff --git a/plugin/shadiao/dujitang.go b/plugin/shadiao/dujitang.go index fe29553bb2..4a134c99e2 100644 --- a/plugin/shadiao/dujitang.go +++ b/plugin/shadiao/dujitang.go @@ -11,7 +11,7 @@ import ( func init() { engine.OnFullMatch("来碗毒鸡汤").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.ReqWith(duURL, "GET", duReferer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), duURL, "GET", duReferer, ua) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return diff --git a/plugin/shadiao/pengyouquan.go b/plugin/shadiao/pengyouquan.go index 3ce0fac90e..31654e2428 100644 --- a/plugin/shadiao/pengyouquan.go +++ b/plugin/shadiao/pengyouquan.go @@ -11,7 +11,7 @@ import ( func init() { engine.OnFullMatch("发个朋友圈").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.ReqWith(pyqURL, "GET", pyqReferer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), pyqURL, "GET", pyqReferer, ua) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return diff --git a/plugin/shadiao/sweetnothings.go b/plugin/shadiao/sweetnothings.go index 31af1f11b1..dcead2fd2f 100644 --- a/plugin/shadiao/sweetnothings.go +++ b/plugin/shadiao/sweetnothings.go @@ -12,7 +12,7 @@ import ( func init() { engine.OnFullMatch("来碗绿茶").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.ReqWith(chayiURL, "GET", loveliveReferer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), chayiURL, "GET", loveliveReferer, ua) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -22,7 +22,7 @@ func init() { }) engine.OnFullMatch("渣我").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.ReqWith(ganhaiURL, "GET", loveliveReferer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), ganhaiURL, "GET", loveliveReferer, ua) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return diff --git a/plugin/shadiao/yduanzi.go b/plugin/shadiao/yduanzi.go index 2c792a17f7..ba8b4ee1e5 100644 --- a/plugin/shadiao/yduanzi.go +++ b/plugin/shadiao/yduanzi.go @@ -14,7 +14,7 @@ import ( func init() { engine.OnFullMatch("讲个段子").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { - data, err := web.ReqWith(yduanziURL, "POST", yduanziReferer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), yduanziURL, "POST", yduanziReferer, ua) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return diff --git a/plugin/vtb_quotation/vtb_quotation.go b/plugin/vtb_quotation/vtb_quotation.go index 4bd1bf9aed..41563f29d5 100644 --- a/plugin/vtb_quotation/vtb_quotation.go +++ b/plugin/vtb_quotation/vtb_quotation.go @@ -2,7 +2,6 @@ package vtbquotation import ( - "crypto/tls" "fmt" "io" "net/http" @@ -22,6 +21,7 @@ import ( control "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/img/text" + "github.com/FloatTech/zbputils/web" "github.com/FloatTech/zbputils/control/order" @@ -255,14 +255,7 @@ func init() { func initRecord(recordFile, recordURL string) { if file.IsNotExist(recordFile) { - transport := http.Transport{ - TLSClientConfig: &tls.Config{ - MaxVersion: tls.VersionTLS12, - }, - } - client := &http.Client{ - Transport: &transport, - } + client := web.NewTLS12Client() req, _ := http.NewRequest("GET", recordURL, nil) req.Header.Set("Content-Type", "application/x-www-form-urlencoded") req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0") diff --git a/plugin/wangyiyun/main.go b/plugin/wangyiyun/main.go index 23f570d7b8..8592e027bc 100644 --- a/plugin/wangyiyun/main.go +++ b/plugin/wangyiyun/main.go @@ -24,7 +24,7 @@ func init() { Help: "wangyiyun \n- 来份网易云热评", }).OnFullMatch("来份网易云热评").SetBlock(true).Limit(ctxext.LimitByUser). Handle(func(ctx *zero.Ctx) { - data, err := web.ReqWith(wangyiyunURL, "GET", wangyiyunReferer, ua) + data, err := web.GetDataWith(web.NewDefaultClient(), wangyiyunURL, "GET", wangyiyunReferer, ua) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return