Skip to content

Commit

Permalink
feat:增加煎蛋网无聊图 (FloatTech#115)
Browse files Browse the repository at this point in the history
* feat:添加煎蛋网无聊图

* fix:修lint

* fix:修改model和名称

* fix:删除不要的驱动

* fix:修改日志错误的地方

* fix:修改权限

* fix:去掉数据库

Co-authored-by: Guohuiyuan <haibaraguo@yeahka.com>
  • Loading branch information
guohuiyuan and Guohuiyuan committed Feb 8, 2022
1 parent 8f6b3fa commit 45edd86
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] 随机书评
Expand All @@ -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] | 获得签到背景
Expand All @@ -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...**

## 使用方法
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" // 摸鱼
Expand Down
1 change: 1 addition & 0 deletions order/prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
PrioGithub
PrioHS
PrioImageFinder
PrioJandan
PrioJueJueZi
PrioLolicon
PrioMinecraft
Expand Down
2 changes: 1 addition & 1 deletion plugin_book_review/book_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions plugin_cpstory/cpstory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
74 changes: 74 additions & 0 deletions plugin_jandan/cron.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
39 changes: 39 additions & 0 deletions plugin_jandan/jandan.go
Original file line number Diff line number Diff line change
@@ -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()
})
}
8 changes: 7 additions & 1 deletion plugin_vtb_quotation/vtb_quotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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数据库已更新")
})
}

0 comments on commit 45edd86

Please sign in to comment.