mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
🔥 精简 log 输出
This commit is contained in:
parent
f2914adb65
commit
a6bd717971
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.18
|
||||
require (
|
||||
github.com/FloatTech/AnimeAPI v1.3.3-0.20220405074902-947bbc912682
|
||||
github.com/FloatTech/sqlite v0.2.1
|
||||
github.com/FloatTech/zbputils v1.3.3-0.20220404063419-35ea3d038087
|
||||
github.com/FloatTech/zbputils v1.3.3-0.20220405145116-f0fb3e428563
|
||||
github.com/antchfx/htmlquery v1.2.4
|
||||
github.com/corona10/goimagehash v1.0.3
|
||||
github.com/fogleman/gg v1.3.0
|
||||
|
||||
4
go.sum
4
go.sum
@ -2,8 +2,8 @@ github.com/FloatTech/AnimeAPI v1.3.3-0.20220405074902-947bbc912682 h1:5pjrW6uotr
|
||||
github.com/FloatTech/AnimeAPI v1.3.3-0.20220405074902-947bbc912682/go.mod h1:YhosmTPUUN8NTwUy3YQCXM9ESQ14x3NUi81cAIbklUs=
|
||||
github.com/FloatTech/sqlite v0.2.1 h1:9t6Me48XJJCIoPy4nLRvcdhcVKfT0c2lilp7SEKROG8=
|
||||
github.com/FloatTech/sqlite v0.2.1/go.mod h1:6NfHRzqOo9RWeMJEoAQVuo51Omd5LFNxCNQhMF02/9U=
|
||||
github.com/FloatTech/zbputils v1.3.3-0.20220404063419-35ea3d038087 h1:yq9lwq5tbKuFEr9eiPeZsORmWKSAErFrzAIPc/1hmuA=
|
||||
github.com/FloatTech/zbputils v1.3.3-0.20220404063419-35ea3d038087/go.mod h1:V2Y8jkxjwACWuJsDCyNVKc+qABfMAUh/mgBYdWBxOPo=
|
||||
github.com/FloatTech/zbputils v1.3.3-0.20220405145116-f0fb3e428563 h1:oQmb9iVoJtONBpQSD9YFWbtTznLTovtKCOBOypWDgsk=
|
||||
github.com/FloatTech/zbputils v1.3.3-0.20220405145116-f0fb3e428563/go.mod h1:V2Y8jkxjwACWuJsDCyNVKc+qABfMAUh/mgBYdWBxOPo=
|
||||
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=
|
||||
|
||||
@ -72,7 +72,7 @@ func init() {
|
||||
}
|
||||
return numcn.EncodeFromFloat64(f)
|
||||
})
|
||||
log.Println("[tts]:", reply)
|
||||
log.Debugln("[tts]:", reply)
|
||||
return reply
|
||||
})))
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/antchfx/htmlquery"
|
||||
log "github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
@ -27,17 +26,21 @@ func init() {
|
||||
|
||||
engine.OnRegex(bilibiliRe).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
bilibiliURL := ctx.State["regex_matched"].([]string)[0]
|
||||
m := parseURL(bilibiliURL)
|
||||
m, err := parseURL(bilibiliURL)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if len(m) != 0 {
|
||||
ctx.Send(m)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func parseURL(bilibiliURL string) (m message.Message) {
|
||||
func parseURL(bilibiliURL string) (m message.Message, err error) {
|
||||
doc, err := htmlquery.LoadURL(bilibiliURL)
|
||||
if err != nil {
|
||||
log.Errorln("[bilibiliparse]:访问的链接为", bilibiliURL, ",错误为", err)
|
||||
return
|
||||
}
|
||||
videoURL := htmlquery.FindOne(doc, "/html/head/meta[@itemprop='url']").Attr[2].Val
|
||||
re := regexp.MustCompile(validRe)
|
||||
|
||||
@ -73,7 +73,6 @@ func init() {
|
||||
dbpath := en.DataFolder()
|
||||
dbfile := dbpath + "push.db"
|
||||
bdb = initialize(dbfile)
|
||||
log.Println("[bilibilipush]加载bilibilipush数据库")
|
||||
}()
|
||||
|
||||
en.OnRegex(`^添加b站订阅\s?(\d+)$`, zero.UserOrGrpAdmin).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
@ -221,7 +220,7 @@ func bilibiliPushDaily() {
|
||||
t := time.NewTicker(time.Second * 10)
|
||||
defer t.Stop()
|
||||
for range t.C {
|
||||
log.Println("-----bilibilipush拉取推送信息-----")
|
||||
log.Debugln("-----bilibilipush拉取推送信息-----")
|
||||
sendDynamic()
|
||||
sendLive()
|
||||
}
|
||||
|
||||
@ -41,7 +41,8 @@ func init() {
|
||||
b := getBookReviewByKeyword(ctx.State["regex_matched"].([]string)[1])
|
||||
data, err := text.RenderToBase64(b.BookReview, text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Println("err:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(data))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -53,7 +54,8 @@ func init() {
|
||||
br := getRandomBookReview()
|
||||
data, err := text.RenderToBase64(br.BookReview, text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Println("err:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Image("base64://" + binary.BytesToString(data))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/antchfx/htmlquery"
|
||||
log "github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
@ -37,85 +36,103 @@ func init() {
|
||||
})
|
||||
engine.OnRegex(`藏头诗\s?([一-龥]{3,10})$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
kw := ctx.State["regex_matched"].([]string)[1]
|
||||
login()
|
||||
err := login()
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
data, err := search(kw, "7", "0")
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
text, err := dealHTML(helper.BytesToString(data))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
text := dealHTML(helper.BytesToString(data))
|
||||
ctx.SendChain(message.Text(text))
|
||||
})
|
||||
|
||||
engine.OnRegex(`藏尾诗\s?([一-龥]{3,10})$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
kw := ctx.State["regex_matched"].([]string)[1]
|
||||
login()
|
||||
err := login()
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
data, err := search(kw, "7", "2")
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
text, err := dealHTML(helper.BytesToString(data))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
text := dealHTML(helper.BytesToString(data))
|
||||
ctx.SendChain(message.Text(text))
|
||||
})
|
||||
}
|
||||
|
||||
func login() {
|
||||
func login() error {
|
||||
gCurCookieJar, _ = cookiejar.New(nil)
|
||||
client := &http.Client{
|
||||
Jar: gCurCookieJar,
|
||||
}
|
||||
request, err := http.NewRequest("GET", loginURL, nil)
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
return err
|
||||
}
|
||||
request.Header.Add("User-Agent", ua)
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
return err
|
||||
}
|
||||
data, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
return err
|
||||
}
|
||||
response.Body.Close()
|
||||
doc, err := htmlquery.Parse(strings.NewReader(helper.BytesToString(data)))
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
return err
|
||||
}
|
||||
csrf = htmlquery.SelectAttr(htmlquery.FindOne(doc, "//input[@name='_csrf']"), "value")
|
||||
return nil
|
||||
}
|
||||
|
||||
func search(kw, zishu, position string) (data []byte, err error) {
|
||||
postStr := fmt.Sprintf("_csrf=%s&kw=%s&zishu=%s&position=%s", url.QueryEscape(csrf), url.QueryEscape(kw), zishu, position)
|
||||
log.Println("postStr:", postStr)
|
||||
client := &http.Client{
|
||||
Jar: gCurCookieJar,
|
||||
}
|
||||
request, err := http.NewRequest("POST", searchURL, strings.NewReader(postStr))
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
return nil, err
|
||||
}
|
||||
request.Header.Add("Referer", referer)
|
||||
request.Header.Add("User-Agent", ua)
|
||||
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
return nil, err
|
||||
}
|
||||
data, err = io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
return nil, err
|
||||
}
|
||||
response.Body.Close()
|
||||
return
|
||||
}
|
||||
|
||||
func dealHTML(data string) (text string) {
|
||||
func dealHTML(data string) (text string, err error) {
|
||||
doc, err := htmlquery.Parse(strings.NewReader(data))
|
||||
if err != nil {
|
||||
log.Errorln("[cangtoushi]:", err)
|
||||
return "", err
|
||||
}
|
||||
text = htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@class='card']/div[@class='card']"))
|
||||
text = strings.ReplaceAll(text, " ", "")
|
||||
text = strings.Replace(text, "\n", "", 1)
|
||||
return text
|
||||
return text, nil
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
@ -31,9 +30,9 @@ func init() {
|
||||
ctx.SendChain(message.Text("少女祈祷中......"))
|
||||
data, err := web.RequestDataWith(web.NewDefaultClient(), coserURL, "GET", "", ua)
|
||||
if err != nil {
|
||||
log.Println("err为:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
|
||||
text := gjson.Get(helper.BytesToString(data), "data.Title").String()
|
||||
m := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Text(text))}
|
||||
ds := ""
|
||||
|
||||
@ -69,7 +69,7 @@ func init() {
|
||||
}
|
||||
LOOP:
|
||||
for i := 0; i < pageTotal; i++ {
|
||||
logrus.Infoln("[jandan]", fmt.Sprintf("处理第%d/%d页...", i, pageTotal))
|
||||
logrus.Debugln("[jandan]", fmt.Sprintf("处理第%d/%d页...", i, pageTotal))
|
||||
doc, err = htmlquery.LoadURL(webpageURL)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
@ -35,14 +34,16 @@ func init() {
|
||||
case 2:
|
||||
data, err := juejuezi(string(toDealStr[0]), string(toDealStr[1]))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text(err))
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text(gjson.Get(helper.BytesToString(data), "text").String()))
|
||||
default:
|
||||
params := ctx.GetWordSlices(string(toDealStr)).Get("slices").Array()
|
||||
data, err := juejuezi(params[0].String(), params[1].String())
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text(err))
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text(gjson.Get(helper.BytesToString(data), "text").String()))
|
||||
}
|
||||
@ -55,13 +56,13 @@ func juejuezi(verb, noun string) (data []byte, err error) {
|
||||
// 提交请求
|
||||
request, err := http.NewRequest("POST", juejueziURL, strings.NewReader(juejueziStr))
|
||||
if err != nil {
|
||||
log.Errorln("[juejuezi]:", err)
|
||||
return nil, err
|
||||
}
|
||||
request.Header.Add("Referer", referer)
|
||||
request.Header.Add("User-Agent", ua)
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
log.Errorln("[juejuezi]:", err)
|
||||
return nil, err
|
||||
}
|
||||
data, err = io.ReadAll(response.Body)
|
||||
response.Body.Close()
|
||||
|
||||
@ -564,7 +564,7 @@ func init() { // 插件主体
|
||||
}
|
||||
ghun := ans[:divi]
|
||||
hash := ans[divi+1:]
|
||||
logrus.Infoln("[manager]收到加群申请, 用户:", ghun, ", hash:", hash)
|
||||
logrus.Debugln("[manager]收到加群申请, 用户:", ghun, ", hash:", hash)
|
||||
ok, reason := checkNewUser(ctx.Event.UserID, ctx.Event.GroupID, ghun, hash)
|
||||
if ok {
|
||||
ctx.SetGroupAddRequest(ctx.Event.Flag, "add", true, "")
|
||||
|
||||
@ -106,10 +106,10 @@ func GetFilledTimer(dateStrs []string, botqq, grp int64, matchDateOnly bool) *Ti
|
||||
urlStr := dateStrs[5]
|
||||
if urlStr != "" { // 是图片url
|
||||
t.URL = urlStr[3:] // utf-8下用为3字节
|
||||
logrus.Println("[群管]" + t.URL)
|
||||
logrus.Debugln("[群管]" + t.URL)
|
||||
if !strings.HasPrefix(t.URL, "http") {
|
||||
t.URL = "illegal"
|
||||
logrus.Println("[群管]url非法!")
|
||||
logrus.Debugln("[群管]url非法!")
|
||||
return &t
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ func (c *Clock) RegisterTimer(ts *Timer, save, isinit bool) bool {
|
||||
if t != ts && ok { // 避免重复注册定时器
|
||||
t.SetEn(false)
|
||||
}
|
||||
logrus.Println("[群管]注册计时器", key)
|
||||
logrus.Infoln("[群管]注册计时器", key)
|
||||
if ts.Cron != "" {
|
||||
var ctx *zero.Ctx
|
||||
if isinit {
|
||||
|
||||
@ -37,7 +37,7 @@ func init() {
|
||||
b, err := os.ReadFile(cfgfile)
|
||||
if err == nil {
|
||||
setupath = helper.BytesToString(b)
|
||||
logrus.Println("[nsetu] set setu dir to", setupath)
|
||||
logrus.Infoln("[nsetu] set setu dir to", setupath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/antchfx/htmlquery"
|
||||
log "github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
@ -44,19 +43,29 @@ func init() {
|
||||
}).OnRegex("^小说([\u4E00-\u9FA5A-Za-z0-9]{1,25})$").SetBlock(true).Limit(ctxext.LimitByUser).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SendChain(message.Text("少女祈祷中......"))
|
||||
login(username, password)
|
||||
err := login(username, password)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
searchKey := ctx.State["regex_matched"].([]string)[1]
|
||||
searchHTML := search(searchKey)
|
||||
searchHTML, err := search(searchKey)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
doc, err := htmlquery.Parse(strings.NewReader(searchHTML))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
htmlTitle := htmlquery.InnerText(htmlquery.FindOne(doc, "/html/head/title"))
|
||||
switch htmlTitle {
|
||||
case websiteTitle:
|
||||
list, err := htmlquery.QueryAll(doc, "//dl[@id='nr']")
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if len(list) != 0 {
|
||||
txt := ""
|
||||
@ -79,7 +88,8 @@ func init() {
|
||||
}
|
||||
data, err := text.RenderToBase64(txt, text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Println("err:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -114,38 +124,39 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func login(username, password string) {
|
||||
func login(username, password string) (err error) {
|
||||
gCurCookieJar, _ = cookiejar.New(nil)
|
||||
client := &http.Client{
|
||||
Jar: gCurCookieJar,
|
||||
}
|
||||
usernameData, err := ub.UTF82GBK(helper.StringToBytes(username))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
return
|
||||
}
|
||||
usernameGbk := helper.BytesToString(usernameData)
|
||||
passwordData, err := ub.UTF82GBK(helper.StringToBytes(password))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
return
|
||||
}
|
||||
passwordGbk := helper.BytesToString(passwordData)
|
||||
loginReq, err := http.NewRequest("POST", loginURL, strings.NewReader(fmt.Sprintf("username=%s&password=%s&usecookie=315360000&action=login&submit=%s", url.QueryEscape(usernameGbk), url.QueryEscape(passwordGbk), submit)))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
return
|
||||
}
|
||||
loginReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
loginReq.Header.Set("User-Agent", ua)
|
||||
loginResp, err := client.Do(loginReq)
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
return
|
||||
}
|
||||
defer loginResp.Body.Close()
|
||||
_ = loginResp.Body.Close()
|
||||
return
|
||||
}
|
||||
|
||||
func search(searchKey string) (searchHTML string) {
|
||||
func search(searchKey string) (searchHTML string, err error) {
|
||||
searchKeyData, err := ub.UTF82GBK(helper.StringToBytes(searchKey))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
return
|
||||
}
|
||||
searchKeyGbk := helper.BytesToString(searchKeyData)
|
||||
client := &http.Client{
|
||||
@ -153,23 +164,23 @@ func search(searchKey string) (searchHTML string) {
|
||||
}
|
||||
searchReq, err := http.NewRequest("POST", searchURL, strings.NewReader(fmt.Sprintf("searchkey=%s&searchtype=all", url.QueryEscape(searchKeyGbk))))
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
return
|
||||
}
|
||||
searchReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
searchReq.Header.Set("User-Agent", ua)
|
||||
searchResp, err := client.Do(searchReq)
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
return
|
||||
}
|
||||
defer searchResp.Body.Close()
|
||||
searchData, err := io.ReadAll(searchResp.Body)
|
||||
_ = searchResp.Body.Close()
|
||||
if err != nil {
|
||||
log.Errorf("[novel] get response for url=%s got error=%s\n", searchURL, err.Error())
|
||||
return
|
||||
}
|
||||
searchData, err = ub.GBK2UTF8(searchData)
|
||||
if err != nil {
|
||||
log.Errorln("[novel]", err)
|
||||
return
|
||||
}
|
||||
searchHTML = helper.BytesToString(searchData)
|
||||
return searchHTML
|
||||
return searchHTML, nil
|
||||
}
|
||||
|
||||
@ -45,7 +45,11 @@ func init() { // 插件主体
|
||||
|
||||
engine.OnFullMatchGroup([]string{"求签", "占卜"}).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
miku := bangoToday(ctx.Event.UserID)
|
||||
miku, err := bangoToday(ctx.Event.UserID)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(
|
||||
message.At(ctx.Event.UserID),
|
||||
message.Image(fmt.Sprintf(bed, miku, 0)),
|
||||
@ -54,9 +58,15 @@ func init() { // 插件主体
|
||||
})
|
||||
engine.OnFullMatchGroup([]string{"解签"}).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
kujiBytes, err := text.RenderToBase64(getKujiByBango(bangoToday(ctx.Event.UserID)), text.FontFile, 400, 20)
|
||||
bg, err := bangoToday(ctx.Event.UserID)
|
||||
if err != nil {
|
||||
log.Errorln("[omikuji]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
kujiBytes, err := text.RenderToBase64(getKujiByBango(bg), text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.At(ctx.Event.UserID), message.Image("base64://"+helper.BytesToString(kujiBytes))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -64,12 +74,12 @@ func init() { // 插件主体
|
||||
})
|
||||
}
|
||||
|
||||
func bangoToday(uid int64) uint8 {
|
||||
func bangoToday(uid int64) (uint8, error) {
|
||||
today, err := strconv.ParseInt(time.Now().Format("20060102"), 10, 64)
|
||||
if err != nil {
|
||||
log.Errorln("string转化为int64格式有问题:", err)
|
||||
return 0, err
|
||||
}
|
||||
seed := uid + today
|
||||
r := rand.New(rand.NewSource(seed))
|
||||
return uint8(r.Intn(100) + 1)
|
||||
return uint8(r.Intn(100) + 1), nil
|
||||
}
|
||||
|
||||
@ -46,7 +46,6 @@ func init() {
|
||||
panic(err)
|
||||
}
|
||||
sdb = initialize(engine.DataFolder() + "score.db")
|
||||
log.Println("[score]加载score数据库")
|
||||
}()
|
||||
engine.OnFullMatch("签到", zero.OnlyGroup).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
@ -69,7 +68,11 @@ func init() {
|
||||
}
|
||||
|
||||
picFile := cachePath + strconv.FormatInt(uid, 10) + today + ".png"
|
||||
initPic(picFile)
|
||||
err := initPic(picFile)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
|
||||
_ = sdb.InsertOrUpdateSignInCountByUID(uid, si.Count+1)
|
||||
|
||||
@ -200,20 +203,21 @@ func getLevel(count int) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func initPic(picFile string) {
|
||||
func initPic(picFile string) error {
|
||||
if file.IsNotExist(picFile) {
|
||||
data, err := web.RequestDataWith(web.NewDefaultClient(), backgroundURL, "GET", referer, ua)
|
||||
if err != nil {
|
||||
log.Errorln("[score]", err)
|
||||
return err
|
||||
}
|
||||
picURL := gjson.Get(string(data), "pic").String()
|
||||
data, err = web.RequestDataWith(web.NewDefaultClient(), picURL, "GET", "", ua)
|
||||
if err != nil {
|
||||
log.Errorln("[score]", err)
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(picFile, data, 0666)
|
||||
if err != nil {
|
||||
log.Errorln("[score]", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ package shindan
|
||||
|
||||
import (
|
||||
"github.com/FloatTech/AnimeAPI/shindanmaker"
|
||||
log "github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
@ -64,7 +63,8 @@ func handlepic(ctx *zero.Ctx) {
|
||||
}
|
||||
data, err := text.RenderToBase64(txt, text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Errorln("[shindan]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
|
||||
@ -74,7 +74,7 @@ func (sdb *sleepdb) sleep(gid, uid int64) (position int, awakeTime time.Duration
|
||||
db.Debug().Model(&SleepManage{}).Create(&st) // newUser not user
|
||||
}
|
||||
} else {
|
||||
log.Println("sleeptime为", st)
|
||||
log.Debugln("sleeptime为", st)
|
||||
awakeTime = now.Sub(st.SleepTime)
|
||||
db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
|
||||
map[string]interface{}{
|
||||
@ -101,7 +101,7 @@ func (sdb *sleepdb) getUp(gid, uid int64) (position int, sleepTime time.Duration
|
||||
db.Debug().Model(&SleepManage{}).Create(&st) // newUser not user
|
||||
}
|
||||
} else {
|
||||
log.Println("sleeptime为", st)
|
||||
log.Debugln("sleeptime为", st)
|
||||
sleepTime = now.Sub(st.SleepTime)
|
||||
db.Debug().Model(&SleepManage{}).Where("group_id = ? and user_id = ?", gid, uid).Update(
|
||||
map[string]interface{}{
|
||||
|
||||
@ -20,12 +20,11 @@ func init() {
|
||||
})
|
||||
go func() {
|
||||
sdb = initialize(engine.DataFolder() + "manage.db")
|
||||
log.Println("[sleepmanage]加载sleepmanage数据库")
|
||||
}()
|
||||
engine.OnFullMatch("早安", isMorning, zero.OnlyGroup).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
position, getUpTime := sdb.getUp(ctx.Event.GroupID, ctx.Event.UserID)
|
||||
log.Println(position, getUpTime)
|
||||
log.Debugln(position, getUpTime)
|
||||
hour, minute, second := timeDuration(getUpTime)
|
||||
if (hour == 0 && minute == 0 && second == 0) || hour >= 24 {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(fmt.Sprintf("早安成功!你是今天第%d个起床的", position)))
|
||||
@ -36,7 +35,7 @@ func init() {
|
||||
engine.OnFullMatch("晚安", isEvening, zero.OnlyGroup).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
position, sleepTime := sdb.sleep(ctx.Event.GroupID, ctx.Event.UserID)
|
||||
log.Println(position, sleepTime)
|
||||
log.Debugln(position, sleepTime)
|
||||
hour, minute, second := timeDuration(sleepTime)
|
||||
if (hour == 0 && minute == 0 && second == 0) || hour >= 24 {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(fmt.Sprintf("晚安成功!你是今天第%d个睡觉的", position)))
|
||||
|
||||
@ -214,7 +214,7 @@ func (vdb *VtbDB) GetVtbList() (uidList []string) {
|
||||
count := gjson.Get(vtbListStr, "#").Int()
|
||||
for i := int64(0); i < count; i++ {
|
||||
item := gjson.Get(vtbListStr, strconv.FormatInt(i, 10))
|
||||
log.Println(item)
|
||||
log.Debugln(item)
|
||||
fc := FirstCategory{
|
||||
FirstCategoryIndex: i,
|
||||
FirstCategoryName: item.Get("name").String(),
|
||||
@ -222,7 +222,7 @@ func (vdb *VtbDB) GetVtbList() (uidList []string) {
|
||||
FirstCategoryIconPath: item.Get("icon_path").String(),
|
||||
FirstCategoryUID: item.Get("uid").String(),
|
||||
}
|
||||
log.Println(fc)
|
||||
log.Debugln(fc)
|
||||
|
||||
if err := db.Debug().Model(&FirstCategory{}).First(&fc, "first_category_uid = ?", fc.FirstCategoryUID).Error; err != nil {
|
||||
if gorm.IsRecordNotFoundError(err) {
|
||||
@ -275,10 +275,10 @@ func (vdb *VtbDB) StoreVtb(uid string) {
|
||||
}
|
||||
|
||||
secondCount := gjson.Get(vtbStr, "data.voices.#").Int()
|
||||
log.Println("二级品类一共有", secondCount)
|
||||
log.Debugln("二级品类一共有", secondCount)
|
||||
for secondIndex := int64(0); secondIndex < secondCount; secondIndex++ {
|
||||
secondItem := gjson.Get(vtbStr, "data.voices."+strconv.FormatInt(secondIndex, 10))
|
||||
log.Println(secondItem)
|
||||
log.Debugln(secondItem)
|
||||
sc := SecondCategory{
|
||||
SecondCategoryName: secondItem.Get("categoryName").String(),
|
||||
SecondCategoryIndex: secondIndex,
|
||||
@ -301,10 +301,10 @@ func (vdb *VtbDB) StoreVtb(uid string) {
|
||||
})
|
||||
}
|
||||
thirdCount := secondItem.Get("voiceList.#").Int()
|
||||
log.Println("三级品类一共有", thirdCount)
|
||||
log.Debugln("三级品类一共有", thirdCount)
|
||||
for thirdIndex := int64(0); thirdIndex < thirdCount; thirdIndex++ {
|
||||
thirdItem := secondItem.Get("voiceList." + strconv.FormatInt(thirdIndex, 10))
|
||||
log.Println(thirdItem)
|
||||
log.Debugln(thirdItem)
|
||||
tc := ThirdCategory{
|
||||
ThirdCategoryName: thirdItem.Get("name").String(),
|
||||
ThirdCategoryIndex: thirdIndex,
|
||||
@ -314,7 +314,7 @@ func (vdb *VtbDB) StoreVtb(uid string) {
|
||||
ThirdCategoryPath: thirdItem.Get("path").String(),
|
||||
ThirdCategoryAuthor: thirdItem.Get("author").String(),
|
||||
}
|
||||
log.Println(tc)
|
||||
log.Debugln(tc)
|
||||
|
||||
if err := db.Debug().Model(&ThirdCategory{}).First(&tc, "first_category_uid = ? and second_category_index = ? and third_category_index = ?",
|
||||
uid, secondIndex, thirdIndex).Error; err != nil {
|
||||
|
||||
@ -13,7 +13,6 @@ import (
|
||||
"time"
|
||||
|
||||
_ "github.com/fumiama/sqlite3" // use sql
|
||||
log "github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
@ -58,14 +57,15 @@ func init() {
|
||||
Repeat() // 不断监听复读
|
||||
db, err := model.Open(dbfile)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
defer db.Close()
|
||||
defer cancel()
|
||||
firstStepImageBytes, err := text.RenderToBase64(db.GetAllFirstCategoryMessage(), text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -85,19 +85,20 @@ func init() {
|
||||
switch step {
|
||||
case 0:
|
||||
firstIndex, err = strconv.Atoi(c.Event.RawMessage)
|
||||
// log.Println(fmt.Sprintf("当前在第%d步", step))
|
||||
// log.Println(fmt.Sprintf("firstIndex:%d,secondIndex:%d,thirdIndex:%d", firstIndex, secondIndex, thirdIndex))
|
||||
// log.Debugln(fmt.Sprintf("当前在第%d步", step))
|
||||
// log.Debugln(fmt.Sprintf("firstIndex:%d,secondIndex:%d,thirdIndex:%d", firstIndex, secondIndex, thirdIndex))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Reply(c.Event.MessageID), message.Text("请输入正确的序号,三次输入错误,指令可退出重输"))
|
||||
errorCount++
|
||||
} else {
|
||||
secondStepMessage := db.GetAllSecondCategoryMessageByFirstIndex(firstIndex)
|
||||
// log.Println(secondStepMessage)
|
||||
// log.Debugln(secondStepMessage)
|
||||
if secondStepMessage == "" {
|
||||
ctx.SendChain(message.Reply(c.Event.MessageID), message.Text("你选择的序号没有内容,请重新选择,三次输入错误,指令可退出重输"))
|
||||
firstStepImageBytes, err := text.RenderToBase64(db.GetAllFirstCategoryMessage(), text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -106,7 +107,8 @@ func init() {
|
||||
} else {
|
||||
secondStepMessageBytes, err := text.RenderToBase64(secondStepMessage, text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(secondStepMessageBytes))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -116,19 +118,20 @@ func init() {
|
||||
}
|
||||
case 1:
|
||||
secondIndex, err = strconv.Atoi(c.Event.RawMessage)
|
||||
// log.Println(fmt.Sprintf("当前在第%d步", step))
|
||||
// log.Println(fmt.Sprintf("firstIndex:%d,secondIndex:%d,thirdIndex:%d", firstIndex, secondIndex, thirdIndex))
|
||||
// log.Debugln(fmt.Sprintf("当前在第%d步", step))
|
||||
// log.Debugln(fmt.Sprintf("firstIndex:%d,secondIndex:%d,thirdIndex:%d", firstIndex, secondIndex, thirdIndex))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Reply(c.Event.MessageID), message.Text("请输入正确的序号,三次输入错误,指令可退出重输"))
|
||||
errorCount++
|
||||
} else {
|
||||
thirdStepMessage := db.GetAllThirdCategoryMessageByFirstIndexAndSecondIndex(firstIndex, secondIndex)
|
||||
// log.Println(thirdStepMessage)
|
||||
// log.Debugln(thirdStepMessage)
|
||||
if thirdStepMessage == "" {
|
||||
ctx.SendChain(message.Reply(c.Event.MessageID), message.Text("你选择的序号没有内容,请重新选择,三次输入错误,指令可退出重输"))
|
||||
secondStepMessageBytes, err := text.RenderToBase64(db.GetAllSecondCategoryMessageByFirstIndex(firstIndex), text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(secondStepMessageBytes))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -137,7 +140,8 @@ func init() {
|
||||
} else {
|
||||
thirdStepMessageBytes, err := text.RenderToBase64(thirdStepMessage, text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(thirdStepMessageBytes))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -147,8 +151,8 @@ func init() {
|
||||
}
|
||||
case 2:
|
||||
thirdIndex, err = strconv.Atoi(c.Event.RawMessage)
|
||||
// log.Println(fmt.Sprintf("当前在第%d步", step))
|
||||
// log.Println(fmt.Sprintf("firstIndex:%d,secondIndex:%d,thirdIndex:%d", firstIndex, secondIndex, thirdIndex))
|
||||
// log.Debugln(fmt.Sprintf("当前在第%d步", step))
|
||||
// log.Debugln(fmt.Sprintf("firstIndex:%d,secondIndex:%d,thirdIndex:%d", firstIndex, secondIndex, thirdIndex))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Reply(c.Event.MessageID), message.Text("请输入正确的序号,三次输入错误,指令可退出重输"))
|
||||
errorCount++
|
||||
@ -160,7 +164,8 @@ func init() {
|
||||
ctx.SendChain(message.Reply(c.Event.MessageID), message.Text("没有内容请重新选择,三次输入错误,指令可退出重输"))
|
||||
firstStepImageBytes, err := text.RenderToBase64(db.GetAllFirstCategoryMessage(), text.FontFile, 400, 20)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id.ID() == 0 {
|
||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||
@ -169,16 +174,16 @@ func init() {
|
||||
step = 1
|
||||
} else {
|
||||
if reg.MatchString(recURL) {
|
||||
// log.Println(reg.FindStringSubmatch(recordUrl)[1])
|
||||
// log.Println(url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]))
|
||||
// log.Debugln(reg.FindStringSubmatch(recordUrl)[1])
|
||||
// log.Debugln(url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]))
|
||||
recURL = strings.ReplaceAll(recURL, reg.FindStringSubmatch(recURL)[1], url.QueryEscape(reg.FindStringSubmatch(recURL)[1]))
|
||||
recURL = strings.ReplaceAll(recURL, "+", "%20")
|
||||
// log.Println(recordUrl)
|
||||
// log.Debugln(recordUrl)
|
||||
}
|
||||
ctx.SendChain(message.Reply(c.Event.MessageID), message.Text("请欣赏《"+tc.ThirdCategoryName+"》"))
|
||||
|
||||
if !re.MatchString(recURL) {
|
||||
log.Errorln("[vtb]:文件格式不匹配")
|
||||
ctx.SendChain(message.Text("ERROR:文件格式不匹配"))
|
||||
return
|
||||
}
|
||||
format := re.FindStringSubmatch(recURL)[1]
|
||||
@ -187,7 +192,11 @@ func init() {
|
||||
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
|
||||
return
|
||||
}
|
||||
initRecord(recordFile, recURL)
|
||||
err = initRecord(recordFile, recURL)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
|
||||
return
|
||||
}
|
||||
@ -205,9 +214,10 @@ func init() {
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
db, err := model.Open(dbfile)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
defer db.Close()
|
||||
tc := db.RandomVtb()
|
||||
fc := db.GetFirstCategoryByFirstUID(tc.FirstCategoryUID)
|
||||
if (tc != model.ThirdCategory{}) && (fc != model.FirstCategory{}) {
|
||||
@ -219,7 +229,7 @@ func init() {
|
||||
}
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("请欣赏"+fc.FirstCategoryName+"的《"+tc.ThirdCategoryName+"》"))
|
||||
if !re.MatchString(recURL) {
|
||||
log.Errorln("[vtb]:文件格式不匹配")
|
||||
ctx.SendChain(message.Text("ERROR:文件格式不匹配"))
|
||||
return
|
||||
}
|
||||
format := re.FindStringSubmatch(recURL)[1]
|
||||
@ -228,10 +238,13 @@ func init() {
|
||||
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
|
||||
return
|
||||
}
|
||||
initRecord(recordFile, recURL)
|
||||
err = initRecord(recordFile, recURL)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + recordFile))
|
||||
}
|
||||
db.Close()
|
||||
})
|
||||
engine.OnFullMatch("更新vtb", zero.SuperUserPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
@ -243,14 +256,15 @@ func init() {
|
||||
}
|
||||
err := db.Close()
|
||||
if err != nil {
|
||||
log.Errorln("[vtb/cron]", err)
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx.Send("vtb数据库已更新")
|
||||
})
|
||||
}
|
||||
|
||||
func initRecord(recordFile, recordURL string) {
|
||||
func initRecord(recordFile, recordURL string) error {
|
||||
if file.IsNotExist(recordFile) {
|
||||
client := web.NewTLS12Client()
|
||||
req, _ := http.NewRequest("GET", recordURL, nil)
|
||||
@ -258,18 +272,17 @@ func initRecord(recordFile, recordURL string) {
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(recordFile, data, 0666)
|
||||
if err != nil {
|
||||
log.Errorln("[vtb]:", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import (
|
||||
"github.com/antchfx/htmlquery"
|
||||
_ "github.com/fumiama/sqlite3" // import sql
|
||||
"github.com/jinzhu/gorm"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// gdb 得分数据库
|
||||
@ -125,27 +124,27 @@ var (
|
||||
emoticonIDList []string
|
||||
)
|
||||
|
||||
func initPageNumber() (maxCgPageNumber, maxEmoticonPageNumber int) {
|
||||
func initPageNumber() (maxCgPageNumber, maxEmoticonPageNumber int, err error) {
|
||||
doc, err := htmlquery.LoadURL(cgURL + "1")
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return
|
||||
}
|
||||
maxCgPageNumber, err = strconv.Atoi(htmlquery.FindOne(doc, commonPageNumberExpr).Data)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return
|
||||
}
|
||||
doc, err = htmlquery.LoadURL(emoticonURL + "1")
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return
|
||||
}
|
||||
maxEmoticonPageNumber, err = strconv.Atoi(htmlquery.FindOne(doc, commonPageNumberExpr).Data)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getPicID(pageNumber int, pictureType string) {
|
||||
func getPicID(pageNumber int, pictureType string) error {
|
||||
var picURL string
|
||||
if pictureType == cgType {
|
||||
picURL = cgURL + strconv.Itoa(pageNumber)
|
||||
@ -154,7 +153,7 @@ func getPicID(pageNumber int, pictureType string) {
|
||||
}
|
||||
doc, err := htmlquery.LoadURL(picURL)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return err
|
||||
}
|
||||
list := htmlquery.Find(doc, "//*[@id='picset-result-list']/ul/div/div[1]/a")
|
||||
for i := 0; i < len(list); i++ {
|
||||
@ -166,16 +165,26 @@ func getPicID(pageNumber int, pictureType string) {
|
||||
emoticonIDList = append(emoticonIDList, picID)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func updatePic() {
|
||||
maxCgPageNumber, maxEmoticonPageNumber := initPageNumber()
|
||||
func updatePic() error {
|
||||
maxCgPageNumber, maxEmoticonPageNumber, err := initPageNumber()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 1; i <= maxCgPageNumber; i++ {
|
||||
getPicID(i, cgType)
|
||||
err = getPicID(i, cgType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
}
|
||||
for i := 1; i <= maxEmoticonPageNumber; i++ {
|
||||
getPicID(i, emoticonType)
|
||||
err = getPicID(i, emoticonType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
}
|
||||
CGLOOP:
|
||||
@ -185,8 +194,11 @@ CGLOOP:
|
||||
mu.RUnlock()
|
||||
if y.PictureList == "" {
|
||||
mu.Lock()
|
||||
storeCgPic(cgIDList[i])
|
||||
err = storeCgPic(cgIDList[i])
|
||||
mu.Unlock()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
break CGLOOP
|
||||
}
|
||||
@ -206,17 +218,18 @@ EMOTICONLOOP:
|
||||
}
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func storeCgPic(picIDStr string) {
|
||||
func storeCgPic(picIDStr string) (err error) {
|
||||
picID, err := strconv.ParseInt(picIDStr, 10, 64)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return
|
||||
}
|
||||
pictureType := cgType
|
||||
doc, err := htmlquery.LoadURL(webPicURL + picIDStr)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return
|
||||
}
|
||||
title := htmlquery.FindOne(doc, "//meta[@name='name']").Attr[1].Val
|
||||
pictureDescription := htmlquery.FindOne(doc, "//meta[@name='description']").Attr[1].Val
|
||||
@ -224,7 +237,7 @@ func storeCgPic(picIDStr string) {
|
||||
re := regexp.MustCompile(reNumber)
|
||||
pictureNumber, err := strconv.Atoi(re.FindString(pictureNumberStr))
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return
|
||||
}
|
||||
pictureList := ""
|
||||
for i := 1; i <= pictureNumber; i++ {
|
||||
@ -236,20 +249,18 @@ func storeCgPic(picIDStr string) {
|
||||
}
|
||||
}
|
||||
err = gdb.insertOrUpdateYmgalByID(picID, title, pictureType, pictureDescription, pictureList)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func storeEmoticonPic(picIDStr string) {
|
||||
func storeEmoticonPic(picIDStr string) error {
|
||||
picID, err := strconv.ParseInt(picIDStr, 10, 64)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return err
|
||||
}
|
||||
pictureType := emoticonType
|
||||
doc, err := htmlquery.LoadURL(webPicURL + picIDStr)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return err
|
||||
}
|
||||
title := htmlquery.FindOne(doc, "//meta[@name='name']").Attr[1].Val
|
||||
pictureDescription := htmlquery.FindOne(doc, "//meta[@name='description']").Attr[1].Val
|
||||
@ -257,7 +268,7 @@ func storeEmoticonPic(picIDStr string) {
|
||||
re := regexp.MustCompile(reNumber)
|
||||
pictureNumber, err := strconv.Atoi(re.FindString(pictureNumberStr))
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
return err
|
||||
}
|
||||
pictureList := ""
|
||||
for i := 1; i <= pictureNumber; i++ {
|
||||
@ -268,8 +279,5 @@ func storeEmoticonPic(picIDStr string) {
|
||||
pictureList += "," + picURL
|
||||
}
|
||||
}
|
||||
err = gdb.insertOrUpdateYmgalByID(picID, title, pictureType, pictureDescription, pictureList)
|
||||
if err != nil {
|
||||
log.Errorln("[ymgal]:", err)
|
||||
}
|
||||
return gdb.insertOrUpdateYmgalByID(picID, title, pictureType, pictureDescription, pictureList)
|
||||
}
|
||||
|
||||
@ -50,7 +50,11 @@ func init() {
|
||||
engine.OnFullMatch("更新gal", zero.SuperUserPermission).SetBlock(true).Handle(
|
||||
func(ctx *zero.Ctx) {
|
||||
ctx.Send("少女祈祷中......")
|
||||
updatePic()
|
||||
err := updatePic()
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR:", err))
|
||||
return
|
||||
}
|
||||
ctx.Send("ymgal数据库已更新")
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user