From 7c5d08b723ea176094efde316d9f54713e57a104 Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 24 Dec 2021 12:32:51 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=20make=20lint=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin_image_finder/keyword.go | 6 +++--- plugin_manager/gist.go | 2 +- plugin_manager/manager.db.go | 4 ++-- plugin_manager/manager.go | 14 ++++++++++---- plugin_moyu/nowork.go | 22 +++++++++++----------- plugin_moyu/run.go | 1 + plugin_nativesetu/main.go | 1 + plugin_vtb_quotation/vtb_quotation.go | 8 ++++---- plugin_wtf/main.go | 8 ++++---- plugin_wtf/model.go | 8 ++++---- utils/file/dl.go | 2 +- utils/file/updater.go | 1 + 12 files changed, 43 insertions(+), 34 deletions(-) diff --git a/plugin_image_finder/keyword.go b/plugin_image_finder/keyword.go index aa90cf95..860d7c1a 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 := randintn(len(soutujson.Illusts)) + rannum := rintn(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 } -// randintn 从json里的30条数据中随机获取一条返回 -func randintn(len int) int { +// rintn 从json里的30条数据中随机获取一条返回 +func rintn(len int) int { rand.Seed(time.Now().UnixNano()) return rand.Intn(len) } diff --git a/plugin_manager/gist.go b/plugin_manager/gist.go index b4aa3692..02396922 100644 --- a/plugin_manager/gist.go +++ b/plugin_manager/gist.go @@ -33,7 +33,7 @@ func checkNewUser(qq, gid int64, ghun, hash string) (bool, string) { // 600s 内验证成功 ok := math.Abs(int(time.Now().Unix()-st)) < 600 if ok { - _ = db.Insert("member", &Member{QQ: qq, Ghun: ghun}) + _ = db.Insert("member", &member{QQ: qq, Ghun: ghun}) return true, "" } return false, "时间戳超时" diff --git a/plugin_manager/manager.db.go b/plugin_manager/manager.db.go index e602d546..5f139ddb 100644 --- a/plugin_manager/manager.db.go +++ b/plugin_manager/manager.db.go @@ -1,11 +1,11 @@ package manager -type Welcome struct { +type welcome struct { GrpID int64 `db:"gid"` Msg string `db:"msg"` } -type Member struct { +type member struct { QQ int64 `db:"qq"` // github username Ghun string `db:"ghun"` diff --git a/plugin_manager/manager.go b/plugin_manager/manager.go index 48aabf27..b00a6e45 100644 --- a/plugin_manager/manager.go +++ b/plugin_manager/manager.go @@ -66,8 +66,14 @@ func init() { // 插件主体 go func() { process.SleepAbout1sTo2s() clock = timer.NewClock(db) - db.Create("welcome", &Welcome{}) - db.Create("member", &Member{}) + err := db.Create("welcome", &welcome{}) + if err != nil { + panic(err) + } + err = db.Create("member", &member{}) + if err != nil { + panic(err) + } }() // 升为管理 engine.OnRegex(`^升为管理.*?(\d+)`, zero.OnlyGroup, zero.SuperUserPermission).SetBlock(true).SetPriority(40). @@ -362,7 +368,7 @@ func init() { // 插件主体 engine.OnNotice().SetBlock(false).FirstPriority(). Handle(func(ctx *zero.Ctx) { if ctx.Event.NoticeType == "group_increase" && ctx.Event.SelfID != ctx.Event.UserID { - var w Welcome + var w welcome err := db.Find("welcome", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10)) if err == nil { ctx.SendChain(message.Text(w.Msg)) @@ -422,7 +428,7 @@ func init() { // 插件主体 // 设置欢迎语 engine.OnRegex(`^设置欢迎语([\s\S]*)$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(40). Handle(func(ctx *zero.Ctx) { - w := &Welcome{ + w := &welcome{ GrpID: ctx.Event.GroupID, Msg: ctx.State["regex_matched"].([]string)[1], } diff --git a/plugin_moyu/nowork.go b/plugin_moyu/nowork.go index e13ad74d..473a6bca 100644 --- a/plugin_moyu/nowork.go +++ b/plugin_moyu/nowork.go @@ -6,35 +6,35 @@ import ( "time" ) -type holiday struct { +// Holiday 节日 +type Holiday struct { name string date time.Time dur time.Duration } // NewHoliday 节日名 天数 年 月 日 -func NewHoliday(name string, dur, year int, month time.Month, day int) *holiday { - return &holiday{name: name, date: time.Date(year, month, day, 0, 0, 0, 0, time.Local), dur: time.Duration(dur) * time.Hour * 24} +func NewHoliday(name string, dur, year int, month time.Month, day int) *Holiday { + return &Holiday{name: name, date: time.Date(year, month, day, 0, 0, 0, 0, time.Local), dur: time.Duration(dur) * time.Hour * 24} } // 获取两个时间相差 -func (h *holiday) String() string { +func (h *Holiday) String() string { d := time.Until(h.date) - if d >= 0 { + switch { + case d >= 0: return "距离" + h.name + "还有: " + strconv.FormatFloat(d.Hours()/24.0, 'f', 2, 64) + "天!" - } else if d+h.dur >= 0 { + case d+h.dur >= 0: return "好好享受 " + h.name + " 假期吧!" - } else { + default: return "今年 " + h.name + " 假期已过" } } func weekend() string { t := time.Now().Weekday() - switch t { - case time.Sunday, time.Saturday: + if t == time.Sunday || t == time.Saturday { return "好好享受周末吧!" - default: - return fmt.Sprintf("距离周末还有:%d天!", 5-t) } + return fmt.Sprintf("距离周末还有:%d天!", 5-t) } diff --git a/plugin_moyu/run.go b/plugin_moyu/run.go index b462de20..728057ea 100644 --- a/plugin_moyu/run.go +++ b/plugin_moyu/run.go @@ -1,3 +1,4 @@ +// Package moyu 摸鱼 package moyu import ( diff --git a/plugin_nativesetu/main.go b/plugin_nativesetu/main.go index 3df398bc..814bf743 100644 --- a/plugin_nativesetu/main.go +++ b/plugin_nativesetu/main.go @@ -1,3 +1,4 @@ +// Package nativesetu 本地setu package nativesetu import ( diff --git a/plugin_vtb_quotation/vtb_quotation.go b/plugin_vtb_quotation/vtb_quotation.go index fab4d3b0..1cd1ce41 100644 --- a/plugin_vtb_quotation/vtb_quotation.go +++ b/plugin_vtb_quotation/vtb_quotation.go @@ -116,8 +116,8 @@ func init() { if reg.MatchString(recordUrl) { // log.Println(reg.FindStringSubmatch(recordUrl)[1]) // log.Println(url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1])) - recordUrl = strings.Replace(recordUrl, reg.FindStringSubmatch(recordUrl)[1], url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]), -1) - recordUrl = strings.Replace(recordUrl, "+", "%20", -1) + recordUrl = strings.ReplaceAll(recordUrl, reg.FindStringSubmatch(recordUrl)[1], url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1])) + recordUrl = strings.ReplaceAll(recordUrl, "+", "%20") // log.Println(recordUrl) } ctx.SendChain(message.Reply(e.MessageID), message.Text("请欣赏《"+tc.ThirdCategoryName+"》")) @@ -149,8 +149,8 @@ func init() { if reg.MatchString(recordUrl) { // log.Println(reg.FindStringSubmatch(recordUrl)[1]) // log.Println(url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1])) - recordUrl = strings.Replace(recordUrl, reg.FindStringSubmatch(recordUrl)[1], url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1]), -1) - recordUrl = strings.Replace(recordUrl, "+", "%20", -1) + recordUrl = strings.ReplaceAll(recordUrl, reg.FindStringSubmatch(recordUrl)[1], url.QueryEscape(reg.FindStringSubmatch(recordUrl)[1])) + recordUrl = strings.ReplaceAll(recordUrl, "+", "%20") // log.Println(recordUrl) } ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("请欣赏"+fc.FirstCategoryName+"的《"+tc.ThirdCategoryName+"》")) diff --git a/plugin_wtf/main.go b/plugin_wtf/main.go index 902521b8..604d87ac 100644 --- a/plugin_wtf/main.go +++ b/plugin_wtf/main.go @@ -1,3 +1,4 @@ +// Package wtf 鬼东西 package wtf import ( @@ -27,7 +28,6 @@ func init() { s := "" for i, w := range table { s += fmt.Sprintf("%02d. %s\n", i, w.name) - i++ } ctx.SendChain(message.Text(s)) }) @@ -43,7 +43,7 @@ func init() { ctx.SendChain(message.Text("ERROR: ", err)) return } - w := NewWtf(i) + w := newWtf(i) if w == nil { ctx.SendChain(message.Text("没有这项内容!")) return @@ -58,9 +58,9 @@ func init() { name = ctx.Event.Sender.NickName var text string if secondname != "" { - text, err = w.Predict(name, secondname) + text, err = w.predict(name, secondname) } else { - text, err = w.Predict(name) + text, err = w.predict(name) } if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) diff --git a/plugin_wtf/model.go b/plugin_wtf/model.go index 1dbaab34..10b7abd4 100644 --- a/plugin_wtf/model.go +++ b/plugin_wtf/model.go @@ -18,12 +18,12 @@ for(i=0; i= 0 && index < len(table) { return table[index] } @@ -128,7 +128,7 @@ type result struct { Msg string `json:"msg"` } -func (w *Wtf) Predict(names ...string) (string, error) { +func (w *wtf) predict(names ...string) (string, error) { name := "" for _, n := range names { name += "/" + url.QueryEscape(n) diff --git a/utils/file/dl.go b/utils/file/dl.go index b555dc9d..5dd6f4fa 100644 --- a/utils/file/dl.go +++ b/utils/file/dl.go @@ -29,9 +29,9 @@ func DownloadTo(url, file string, chkcrt bool) error { f, err = os.Create(file) if err == nil { _, err = io.Copy(f, resp.Body) - resp.Body.Close() f.Close() } + resp.Body.Close() } return err } diff --git a/utils/file/updater.go b/utils/file/updater.go index 648e9643..b6cb7c02 100644 --- a/utils/file/updater.go +++ b/utils/file/updater.go @@ -23,6 +23,7 @@ var ( lzmu sync.Mutex ) +// GetLazyData 获取懒加载数据 func GetLazyData(path string, isReturnDataBytes, isDataMustEqual bool) ([]byte, error) { var data []byte var resp *http.Response