forked from FloatTech/ZeroBot-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat:添加煎蛋网无聊图 * fix:修lint * fix:修改model和名称 * fix:删除不要的驱动 * fix:修改日志错误的地方 * fix:修改权限 * fix:去掉数据库 Co-authored-by: Guohuiyuan <haibaraguo@yeahka.com>
- Loading branch information
1 parent
8f6b3fa
commit 45edd86
Showing
8 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ const ( | |
PrioGithub | ||
PrioHS | ||
PrioImageFinder | ||
PrioJandan | ||
PrioJueJueZi | ||
PrioLolicon | ||
PrioMinecraft | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters