make lint happy

This commit is contained in:
fumiama 2021-12-26 15:16:42 +08:00
parent cb44758036
commit 0a95f3198b
6 changed files with 27 additions and 25 deletions

View File

@ -21,8 +21,8 @@ const (
var db = sql.Sqlite{DBPath: dbfile} var db = sql.Sqlite{DBPath: dbfile}
type Text struct { type text struct {
Id int64 `db:"id"` ID int64 `db:"id"`
Data string `db:"data"` Data string `db:"data"`
} }
@ -35,7 +35,7 @@ func init() {
} }
err = LoadText() err = LoadText()
if err == nil { if err == nil {
err = db.Create("text", &Text{}) err = db.Create("text", &text{})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -57,12 +57,12 @@ func LoadText() error {
func AddText(txt string) error { func AddText(txt string) error {
s := md5.Sum(helper.StringToBytes(txt)) s := md5.Sum(helper.StringToBytes(txt))
i := binary.LittleEndian.Uint64(s[:8]) i := binary.LittleEndian.Uint64(s[:8])
return db.Insert("text", &Text{Id: int64(i), Data: txt}) return db.Insert("text", &text{ID: int64(i), Data: txt})
} }
// RandText 随机小作文 // RandText 随机小作文
func RandText() string { func RandText() string {
var t Text var t text
err := db.Pick("text", &t) err := db.Pick("text", &t)
if err != nil { if err != nil {
return err.Error() return err.Error()
@ -72,7 +72,7 @@ func RandText() string {
// HentaiText 发大病 // HentaiText 发大病
func HentaiText() string { func HentaiText() string {
var t Text var t text
err := db.Find("text", &t, "where id = -3802576048116006195") err := db.Find("text", &t, "where id = -3802576048116006195")
if err != nil { if err != nil {
return err.Error() return err.Error()

View File

@ -54,14 +54,15 @@ func init() {
ctx.SendChain(message.Text("少女祈祷中......")) ctx.SendChain(message.Text("少女祈祷中......"))
login(username, password) login(username, password)
searchKey := ctx.State["regex_matched"].([]string)[1] searchKey := ctx.State["regex_matched"].([]string)[1]
searchHtml := search(searchKey) searchHTML := search(searchKey)
var m message.Message var m message.Message
doc, err := htmlquery.Parse(strings.NewReader(searchHtml)) doc, err := htmlquery.Parse(strings.NewReader(searchHTML))
if err != nil { if err != nil {
log.Errorln("[novel]", err) log.Errorln("[novel]", err)
} }
htmlTitle := htmlquery.InnerText(htmlquery.FindOne(doc, "/html/head/title")) htmlTitle := htmlquery.InnerText(htmlquery.FindOne(doc, "/html/head/title"))
if htmlTitle == websiteTitle { switch htmlTitle {
case websiteTitle:
list, err := htmlquery.QueryAll(doc, "//dl[@id='nr']") list, err := htmlquery.QueryAll(doc, "//dl[@id='nr']")
if err != nil { if err != nil {
log.Errorln("[novel]", err) log.Errorln("[novel]", err)
@ -97,16 +98,16 @@ func init() {
} }
} else { } else {
text := htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@id='tipss']")) text := htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@id='tipss']"))
text = strings.Replace(text, " ", "", -1) text = strings.ReplaceAll(text, " ", "")
text = strings.Replace(text, "本站", websiteURL, -1) text = strings.ReplaceAll(text, "本站", websiteURL)
ctx.SendChain(message.Text(text)) ctx.SendChain(message.Text(text))
} }
} else if htmlTitle == errorTitle { case errorTitle:
ctx.SendChain(message.Text(errorTitle)) ctx.SendChain(message.Text(errorTitle))
text := htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@style='text-align: center;padding:10px']")) text := htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@style='text-align: center;padding:10px']"))
text = strings.Replace(text, " ", "", -1) text = strings.ReplaceAll(text, " ", "")
ctx.SendChain(message.Text(text)) ctx.SendChain(message.Text(text))
} else { default:
bookName := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:book_name']"), "content") bookName := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:book_name']"), "content")
category := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:category']"), "content") category := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:category']"), "content")
author := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:author']"), "content") author := htmlquery.SelectAttr(htmlquery.FindOne(doc, "//meta[@property='og:novel:author']"), "content")
@ -153,7 +154,7 @@ func login(username, password string) {
defer loginResp.Body.Close() defer loginResp.Body.Close()
} }
func search(searchKey string) (searchHtml string) { func search(searchKey string) (searchHTML string) {
searchKeyData, err := ub.UTF82GBK(helper.StringToBytes(searchKey)) searchKeyData, err := ub.UTF82GBK(helper.StringToBytes(searchKey))
if err != nil { if err != nil {
log.Errorln("[novel]", err) log.Errorln("[novel]", err)
@ -181,6 +182,6 @@ func search(searchKey string) (searchHtml string) {
if err != nil { if err != nil {
log.Errorln("[novel]", err) log.Errorln("[novel]", err)
} }
searchHtml = helper.BytesToString(searchData) searchHTML = helper.BytesToString(searchData)
return searchHtml return searchHTML
} }

View File

@ -1,10 +1,3 @@
/*
* @Author: Kanri
* @Date: 2021-10-15 21:23:14
* @LastEditors: Kanri
* @LastEditTime: 2021-10-15 21:42:51
* @Description:
*/
// Package shindan 基于 https://shindanmaker.com 的测定小功能 // Package shindan 基于 https://shindanmaker.com 的测定小功能
package shindan package shindan

View File

@ -1,3 +1,4 @@
// Package tracemoe 搜番
package tracemoe package tracemoe
import ( import (

View File

@ -96,12 +96,18 @@ func (vdb *VtbDB) GetAllFirstCategoryMessage() string {
rows, err := db.Model(&FirstCategory{}).Rows() rows, err := db.Model(&FirstCategory{}).Rows()
if err != nil { if err != nil {
logrus.Errorln("[vtb/model]数据库读取错误", err) logrus.Errorln("[vtb/model]数据库读取错误", err)
return ""
} }
if rows == nil { if rows == nil {
return "" return ""
} }
defer rows.Close()
for rows.Next() { for rows.Next() {
db.ScanRows(rows, &fc) err = db.ScanRows(rows, &fc)
if err != nil {
logrus.Errorln("[vtb/model]数据库读取错误", err)
return ""
}
// logrus.Println(fc) // logrus.Println(fc)
firstStepMessage = firstStepMessage + strconv.FormatInt(fc.FirstCategoryIndex, 10) + ". " + fc.FirstCategoryName + "\n" firstStepMessage = firstStepMessage + strconv.FormatInt(fc.FirstCategoryIndex, 10) + ". " + fc.FirstCategoryName + "\n"
} }

View File

@ -1,3 +1,4 @@
// Package binary 数据处理
package binary package binary
import ( import (