Skip to content

Commit

Permalink
🔥 精简 log 输出
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Apr 5, 2022
1 parent f2914ad commit a6bd717
Show file tree
Hide file tree
Showing 24 changed files with 222 additions and 152 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion plugin/ai_reply/ai_tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func init() {
}
return numcn.EncodeFromFloat64(f)
})
log.Println("[tts]:", reply)
log.Debugln("[tts]:", reply)
return reply
})))
}
Expand Down
11 changes: 7 additions & 4 deletions plugin/bilibili_parse/bilibili_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions plugin/bilibili_push/bilibili_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
Expand Down
6 changes: 4 additions & 2 deletions plugin/book_review/book_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:可能被风控了"))
Expand All @@ -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:可能被风控了"))
Expand Down
55 changes: 36 additions & 19 deletions plugin/cangtoushi/cangtoushi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
5 changes: 2 additions & 3 deletions plugin/coser/coser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 := ""
Expand Down
2 changes: 1 addition & 1 deletion plugin/jandan/jandan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 6 additions & 5 deletions plugin/juejuezi/juejuezi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()))
}
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion plugin/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down
4 changes: 2 additions & 2 deletions plugin/manager/timer/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/manager/timer/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion plugin/nativesetu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Loading

0 comments on commit a6bd717

Please sign in to comment.