From 45edd86cb80b2afa907a362928b919de809a9af6 Mon Sep 17 00:00:00 2001 From: himawari <54976075+guohuiyuan@users.noreply.github.com> Date: Tue, 8 Feb 2022 15:05:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E7=85=8E=E8=9B=8B?= =?UTF-8?q?=E7=BD=91=E6=97=A0=E8=81=8A=E5=9B=BE=20(#115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat:添加煎蛋网无聊图 * fix:修lint * fix:修改model和名称 * fix:删除不要的驱动 * fix:修改日志错误的地方 * fix:修改权限 * fix:去掉数据库 Co-authored-by: Guohuiyuan --- README.md | 6 ++- main.go | 1 + order/prio.go | 1 + plugin_book_review/book_review.go | 2 +- plugin_cpstory/cpstory.go | 4 +- plugin_jandan/cron.go | 74 +++++++++++++++++++++++++++ plugin_jandan/jandan.go | 39 ++++++++++++++ plugin_vtb_quotation/vtb_quotation.go | 8 ++- 8 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 plugin_jandan/cron.go create mode 100644 plugin_jandan/jandan.go diff --git a/README.md b/README.md index 4fb02707..e0503d63 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,7 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地 - **vtb语录** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation"` - [x] vtb语录 - [x] 随机vtb + - [x] 更新vtb - **书评** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_book_review"` - [x] 书评[xxx] - [x] 随机书评 @@ -252,7 +253,7 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地 - [x] 藏尾诗[xxx] - **cp短打** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_cpstory"` - [x] 组cp[@xxx][@xxx] - - [x] 组cp大老师 雪乃 + - [x] 磕cp大老师 雪乃 - **签到得分** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_score"` - [x] 签到 - [x] 获得签到背景[@xxx] | 获得签到背景 @@ -269,6 +270,9 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地 - [x] 来份网易云热评 - **b站视频链接解析** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili_parse"` - [x] https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA +- **煎蛋网无聊图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_jandan"` + - [x] 来份屌图 + - [x] 更新屌图 - **TODO...** ## 使用方法 diff --git a/main.go b/main.go index 45492d9c..e95ca3ca 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny" // 笑话 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_gif" // 制图 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_jandan" // 煎蛋网无聊图 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_juejuezi" // 绝绝子生成器 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager _ "github.com/FloatTech/ZeroBot-Plugin/plugin_moyu" // 摸鱼 diff --git a/order/prio.go b/order/prio.go index 9ba1be17..00c97ddb 100644 --- a/order/prio.go +++ b/order/prio.go @@ -29,6 +29,7 @@ const ( PrioGithub PrioHS PrioImageFinder + PrioJandan PrioJueJueZi PrioLolicon PrioMinecraft diff --git a/plugin_book_review/book_review.go b/plugin_book_review/book_review.go index bb024a51..3a55426f 100644 --- a/plugin_book_review/book_review.go +++ b/plugin_book_review/book_review.go @@ -7,7 +7,7 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/utils/helper" - control "github.com/FloatTech/zbputils/control" + "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/txt2img" "github.com/FloatTech/ZeroBot-Plugin/order" diff --git a/plugin_cpstory/cpstory.go b/plugin_cpstory/cpstory.go index c82c4f7b..218a8a31 100644 --- a/plugin_cpstory/cpstory.go +++ b/plugin_cpstory/cpstory.go @@ -17,7 +17,7 @@ import ( func init() { engine := control.Register("cpstory", order.PrioCPStory, &control.Options{ DisableOnDefault: false, - Help: "cp短打\n- 组cp[@xxx][@xxx]\n- 组cp大老师 雪乃", + Help: "cp短打\n- 组cp[@xxx][@xxx]\n- 磕cp大老师 雪乃", }) engine.OnRegex("^组cp.*?(\\d+).*?(\\d+)", zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { cs := getRandomCpStory() @@ -29,7 +29,7 @@ func init() { text = strings.ReplaceAll(text, cs.Shou, gong) ctx.SendChain(message.Text(text)) }) - engine.OnPrefix("组cp").SetBlock(true).Handle(func(ctx *zero.Ctx) { + engine.OnPrefix("磕cp").SetBlock(true).Handle(func(ctx *zero.Ctx) { cs := getRandomCpStory() params := strings.Split(ctx.State["args"].(string), " ") if len(params) < 2 { diff --git a/plugin_jandan/cron.go b/plugin_jandan/cron.go new file mode 100644 index 00000000..9a54bd2d --- /dev/null +++ b/plugin_jandan/cron.go @@ -0,0 +1,74 @@ +package jandan + +import ( + "github.com/FloatTech/zbputils/process" + "github.com/antchfx/htmlquery" + "github.com/fumiama/cron" + log "github.com/sirupsen/logrus" + "regexp" + "strconv" +) + +var ( + chanPicture = make(chan string, 100000) + pageTotal int +) + +func init() { + go func() { + process.SleepAbout1sTo2s() + scorePicture() + log.Println("[jandan/cron] 开启jandan数据库日常更新") + jandanDaily() + }() + travelWebpage() +} + +func jandanDaily() { + c := cron.New() + _, err := c.AddFunc("10 4 * * *", func() { travelWebpage() }) + if err != nil { + log.Errorln("定时任务有错误:", err) + } else { + log.Println("开启jandan数据库定时任务") + c.Start() + } +} + +func travelWebpage() { + pictureList = pictureList[0:0] + webpageURL := jandanPictureURL + doc, err := htmlquery.LoadURL(webpageURL) + if err != nil { + log.Errorln("[jandan]:", err) + } + re := regexp.MustCompile(`\d+`) + pageTotal, err = strconv.Atoi(re.FindString(htmlquery.FindOne(doc, "//*[@id='comments']/div[2]/div/span[@class='current-comment-page']/text()").Data)) + if err != nil { + log.Errorln("[jandan]:", err) + } + for i := 0; i < pageTotal; i++ { + doc, err = htmlquery.LoadURL(webpageURL) + if err != nil { + log.Errorln("[jandan]:", err) + } + picList, err := htmlquery.QueryAll(doc, "//*[@class='view_img_link']") + if err != nil { + log.Errorln("[jandan]:", err) + } + if len(picList) != 0 { + for _, v := range picList { + chanPicture <- "https:" + v.Attr[0].Val + } + } + if i != pageTotal-1 { + webpageURL = "https:" + htmlquery.FindOne(doc, "//*[@id='comments']/div[@class='comments']/div[@class='cp-pagenavi']/a[@class='previous-comment-page']").Attr[1].Val + } + } +} + +func scorePicture() { + for pictureURL := range chanPicture { + pictureList = append(pictureList, pictureURL) + } +} diff --git a/plugin_jandan/jandan.go b/plugin_jandan/jandan.go new file mode 100644 index 00000000..ff28929f --- /dev/null +++ b/plugin_jandan/jandan.go @@ -0,0 +1,39 @@ +// Package jandan 煎蛋网无聊图 +package jandan + +import ( + "github.com/FloatTech/ZeroBot-Plugin/order" + "github.com/FloatTech/zbputils/control" + "github.com/wdvxdr1123/ZeroBot/message" + "math/rand" + "time" + + zero "github.com/wdvxdr1123/ZeroBot" +) + +const ( + jandanPictureURL = "http://jandan.net/pic" +) + +var ( + pictureList []string +) + +func init() { + engine := control.Register("jandan", order.PrioJandan, &control.Options{ + DisableOnDefault: false, + Help: "煎蛋网无聊图\n- 来份屌图\n- 更新屌图\n", + }) + + engine.OnFullMatch("来份屌图").SetBlock(true). + Handle(func(ctx *zero.Ctx) { + rand.Seed(time.Now().Unix()) + ctx.SendChain(message.Image(pictureList[rand.Intn(len(pictureList))])) + }) + + engine.OnFullMatch("更新屌图", zero.SuperUserPermission).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + ctx.Send("少女更新中......") + travelWebpage() + }) +} diff --git a/plugin_vtb_quotation/vtb_quotation.go b/plugin_vtb_quotation/vtb_quotation.go index 1517e6c1..52b437c4 100644 --- a/plugin_vtb_quotation/vtb_quotation.go +++ b/plugin_vtb_quotation/vtb_quotation.go @@ -29,7 +29,7 @@ const ( var engine = control.Register("vtbquotation", order.PrioVtbQuotation, &control.Options{ DisableOnDefault: false, - Help: "vtbkeyboard.moe\n- vtb语录\n- 随机vtb", + Help: "vtbkeyboard.moe\n- vtb语录\n- 随机vtb\n- 更新vtb\n", }) func init() { @@ -195,4 +195,10 @@ func init() { } db.Close() }) + engine.OnFullMatch("更新vtb", zero.SuperUserPermission).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + ctx.Send("少女祈祷中......") + vtbData() + ctx.Send("vtb数据库已更新") + }) }