From 7109e30d93501c933f0758df1fad0963ec4dabf6 Mon Sep 17 00:00:00 2001 From: fumiama Date: Mon, 24 Jan 2022 21:48:21 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E2=9A=A1=EF=B8=8F=20?= =?UTF-8?q?=F0=9F=94=A5=20modify=20wyy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++- main.go | 1 + plugin_wangyiyun/main.go | 69 +++++++++++++++++++--------------------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index c2992da8..9f1b6e49 100644 --- a/README.md +++ b/README.md @@ -252,12 +252,14 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地 - **骂人** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_curse"` - [x] 骂我 - [x] 大力骂我 -- **b站推送** `_ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili_push"` +- **b站推送** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili_push"` - [x] 添加订阅[uid] - [x] 取消订阅[uid] - [x] 取消动态订阅[uid] - [x] 取消直播订阅[uid] - [x] 推送列表 +- **网易云音乐热评** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_wangyiyun"` + - [x] 来份网易云热评 - **TODO...** ## 使用方法 diff --git a/main.go b/main.go index 4e72489a..bece30eb 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin_score" // 分数 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_shadiao" // 沙雕app _ "github.com/FloatTech/ZeroBot-Plugin/plugin_shindan" // 测定 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_wangyiyun" // 网易云音乐热评 // b站相关 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // 查询b站用户信息 diff --git a/plugin_wangyiyun/main.go b/plugin_wangyiyun/main.go index 2787f55c..58fd246d 100644 --- a/plugin_wangyiyun/main.go +++ b/plugin_wangyiyun/main.go @@ -1,43 +1,40 @@ +// Package wangyiyun 网易云音乐热评 package wangyiyun -import -( - - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" - control "github.com/FloatTech/zbputils/control" - "github.com/FloatTech/zbputils/web" - "github.com/FloatTech/ZeroBot-Plugin/order" - "github.com/wdvxdr1123/ZeroBot/extension/rate" +import ( "time" + + "github.com/FloatTech/zbputils/control" + "github.com/FloatTech/zbputils/web" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/extension/rate" + "github.com/wdvxdr1123/ZeroBot/message" + "github.com/wdvxdr1123/ZeroBot/utils/helper" + + "github.com/FloatTech/ZeroBot-Plugin/order" ) -const( - wangyiyunURL = "http://ovooa.com/API/wyrp/api.php?type=text" - wangyiyunReferer = "http://ovooa.com/" - ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" - ) - -var( - engine = control.Register("wangyiyun",order.PrioWangYiYun, &control.Options{ - +const ( + wangyiyunURL = "http://ovooa.com/API/wyrp/api.php?type=text" + wangyiyunReferer = "http://ovooa.com/" + ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" +) + +func init() { + limit := rate.NewManager(time.Minute, 60) + control.Register("wangyiyun", order.PrioWangYiYun, &control.Options{ DisableOnDefault: false, - Help: "wangyiyun \n- 来份网易云热评", - }) - limit = rate.NewManager(time.Minute, 60) - ) -func init() { - engine.OnFullMatch("来份网易云热评").SetBlock(true). - Handle(func(ctx *zero.Ctx) { - if !limit.Load(ctx.Event.GroupID).Acquire() { - return - } - data, err := web.ReqWith(wangyiyunURL, "GET", wangyiyunReferer, ua) - - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } - - }) + Help: "wangyiyun \n- 来份网易云热评", + }).OnFullMatch("来份网易云热评").SetBlock(true). + Handle(func(ctx *zero.Ctx) { + if !limit.Load(ctx.Event.GroupID).Acquire() { + return + } + data, err := web.ReqWith(wangyiyunURL, "GET", wangyiyunReferer, ua) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + ctx.SendChain(message.Text(helper.BytesToString(data))) + }) }