From 3939e0760f6ae9a4f39ab8e3dac7024d71f21a0c Mon Sep 17 00:00:00 2001 From: fumiama Date: Sun, 26 Dec 2021 21:59:48 +0800 Subject: [PATCH] make lint happy --- plugin_image_finder/keyword.go | 8 ++--- plugin_moyu/nowork.go | 2 +- plugin_omikuji/migrate/main.go | 46 ----------------------------- plugin_shadiao/shadiao.go | 18 +++++------ plugin_sleep_manage/model/model.go | 3 +- plugin_vtb_quotation/model/model.go | 15 ++++++++-- utils/math/conv.go | 1 + 7 files changed, 29 insertions(+), 64 deletions(-) delete mode 100644 plugin_omikuji/migrate/main.go diff --git a/plugin_image_finder/keyword.go b/plugin_image_finder/keyword.go index 860d7c1a..27e329a8 100644 --- a/plugin_image_finder/keyword.go +++ b/plugin_image_finder/keyword.go @@ -70,7 +70,7 @@ func init() { keyword := ctx.State["regex_matched"].([]string)[1] soutujson := soutuapi(keyword) pom1 := "https://i.pixiv.re" - rannum := rintn(len(soutujson.Illusts)) + rannum := randintn(len(soutujson.Illusts)) pom2 := soutujson.Illusts[rannum].ImageUrls.Medium[19:] ctx.SendChain(message.Image(pom1 + pom2)) }) @@ -102,8 +102,8 @@ func soutuapi(keyword string) *resultjson { return result } -// rintn 从json里的30条数据中随机获取一条返回 -func rintn(len int) int { +// randintn 从json里的30条数据中随机获取一条返回 +func randintn(n int) int { rand.Seed(time.Now().UnixNano()) - return rand.Intn(len) + return rand.Intn(n) } diff --git a/plugin_moyu/nowork.go b/plugin_moyu/nowork.go index 3f7e653e..af27f7dd 100644 --- a/plugin_moyu/nowork.go +++ b/plugin_moyu/nowork.go @@ -46,7 +46,7 @@ func GetHoliday(name string) *Holiday { return h } -// 获取两个时间相差 +// String 获取两个时间相差 func (h *Holiday) String() string { d := time.Until(h.date) switch { diff --git a/plugin_omikuji/migrate/main.go b/plugin_omikuji/migrate/main.go deleted file mode 100644 index 5d149d83..00000000 --- a/plugin_omikuji/migrate/main.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strconv" - - "github.com/FloatTech/ZeroBot-Plugin/utils/sql" -) - -type signature struct { - Id uint64 `db:"id"` - Text string `db:"text"` -} - -type kuji struct { - Id uint8 `db:"id"` - Text string `db:"text"` -} - -func main() { - db := &sql.Sqlite{DBPath: os.Args[1]} - newdb := &sql.Sqlite{DBPath: os.Args[2]} - err := newdb.Create("kuji", &kuji{}) - if err != nil { - panic(err) - } - err = db.Create("signature", &signature{}) - if err != nil { - panic(err) - } - - fmt.Println(db.Count("signature")) - s := &signature{} - k := &kuji{} - for i := 1; i <= 100; i++ { - db.Find("signature", s, "where id = "+strconv.Itoa(i)) - fmt.Println("insert: ", s.Text[:57]) - k.Id = uint8(i) - k.Text = s.Text - newdb.Insert("kuji", k) - } - - db.Close() - newdb.Close() -} diff --git a/plugin_shadiao/shadiao.go b/plugin_shadiao/shadiao.go index 6af2ba96..760b46f1 100644 --- a/plugin_shadiao/shadiao.go +++ b/plugin_shadiao/shadiao.go @@ -10,21 +10,21 @@ import ( ) const ( - chpURL = "https://chp.shadiao.app/api.php" - duURL = "https://du.shadiao.app/api.php" - pyqURL = "https://pyq.shadiao.app/api.php" - yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi" - chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0" - ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1" - zuanURL = "https://zuanbot.com/api.php?level=min&lang=zh_cn" + chpURL = "https://chp.shadiao.app/api.php" + duURL = "https://du.shadiao.app/api.php" + pyqURL = "https://pyq.shadiao.app/api.php" + yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi" + chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0" + ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1" + // zuanURL = "https://zuanbot.com/api.php?level=min&lang=zh_cn" ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" chpReferer = "https://chp.shadiao.app/" duReferer = "https://du.shadiao.app/" pyqReferer = "https://pyq.shadiao.app/" yduanziReferer = "http://www.yduanzi.com/?utm_source=shadiao.app" loveliveReferer = "https://lovelive.tools/" - zuanReferer = "https://zuanbot.com/" - prio = 10 + // zuanReferer = "https://zuanbot.com/" + prio = 10 ) var ( diff --git a/plugin_sleep_manage/model/model.go b/plugin_sleep_manage/model/model.go index aa3717a7..96907612 100644 --- a/plugin_sleep_manage/model/model.go +++ b/plugin_sleep_manage/model/model.go @@ -37,9 +37,8 @@ func Open(dbpath string) (*SleepDB, error) { db, err := gorm.Open("sqlite3", dbpath) if err != nil { return nil, err - } else { - return (*SleepDB)(db), nil } + return (*SleepDB)(db), nil } // Close 关闭 diff --git a/plugin_vtb_quotation/model/model.go b/plugin_vtb_quotation/model/model.go index cb9e6e85..e1edef1b 100644 --- a/plugin_vtb_quotation/model/model.go +++ b/plugin_vtb_quotation/model/model.go @@ -10,13 +10,15 @@ import ( "time" "github.com/jinzhu/gorm" - _ "github.com/logoove/sqlite" + _ "github.com/logoove/sqlite" // import sql "github.com/sirupsen/logrus" "github.com/tidwall/gjson" ) +// VtbDB vtb 数据库 type VtbDB gorm.DB +// Initialize ... func Initialize(dbpath string) *VtbDB { var err error if _, err = os.Stat(dbpath); err != nil || os.IsNotExist(err) { @@ -35,6 +37,7 @@ func Initialize(dbpath string) *VtbDB { return (*VtbDB)(gdb) } +// Open ... func Open(dbpath string) (*VtbDB, error) { db, err := gorm.Open("sqlite3", dbpath) if err != nil { @@ -54,6 +57,7 @@ type FirstCategory struct { FirstCategoryIconPath string `gorm:"column:first_category_icon_path"` } +// TableName ... func (FirstCategory) TableName() string { return "first_category" } @@ -68,6 +72,7 @@ type SecondCategory struct { SecondCategoryDescription string `gorm:"column:second_category_description"` } +// TableName ... func (SecondCategory) TableName() string { return "second_category" } @@ -84,6 +89,7 @@ type ThirdCategory struct { ThirdCategoryDescription string `gorm:"column:third_category_description"` } +// TableName ... func (ThirdCategory) TableName() string { return "third_category" } @@ -163,7 +169,7 @@ func (vdb *VtbDB) GetAllThirdCategoryMessageByFirstIndexAndSecondIndex(firstInde return ThirdStepMessage } -// GetThirdCategory +// GetThirdCategory ... func (vdb *VtbDB) GetThirdCategory(firstIndex, secondIndex, thirdIndex int) ThirdCategory { db := (*gorm.DB)(vdb) var fc FirstCategory @@ -173,6 +179,7 @@ func (vdb *VtbDB) GetThirdCategory(firstIndex, secondIndex, thirdIndex int) Thir return tc } +// RandomVtb ... func (vdb *VtbDB) RandomVtb() ThirdCategory { db := (*gorm.DB)(vdb) rand.Seed(time.Now().UnixNano()) @@ -185,6 +192,7 @@ func (vdb *VtbDB) RandomVtb() ThirdCategory { return tc } +// GetFirstCategoryByFirstUid ... func (vdb *VtbDB) GetFirstCategoryByFirstUid(firstUid string) FirstCategory { db := (*gorm.DB)(vdb) var fc FirstCategory @@ -193,6 +201,7 @@ func (vdb *VtbDB) GetFirstCategoryByFirstUid(firstUid string) FirstCategory { return fc } +// Close ... func (vdb *VtbDB) Close() error { db := (*gorm.DB)(vdb) return db.Close() @@ -200,6 +209,7 @@ func (vdb *VtbDB) Close() error { const vtbUrl = "https://vtbkeyboard.moe/api/get_vtb_list" +// GetVtbList ... func (vdb *VtbDB) GetVtbList() (uidList []string) { db := (*gorm.DB)(vdb) client := &http.Client{} @@ -261,6 +271,7 @@ func (vdb *VtbDB) GetVtbList() (uidList []string) { return uidList } +// StoreVtb ... func (vdb *VtbDB) StoreVtb(uid string) { db := (*gorm.DB)(vdb) vtbUrl := "https://vtbkeyboard.moe/api/get_vtb_page?uid=" + uid diff --git a/utils/math/conv.go b/utils/math/conv.go index 4f99cce2..765bda9e 100644 --- a/utils/math/conv.go +++ b/utils/math/conv.go @@ -2,6 +2,7 @@ package math import "strconv" +// Str2Int64 string to int64 func Str2Int64(str string) int64 { val, _ := strconv.ParseInt(str, 10, 64) return val