From ce406d8f552e99cf497eee43588a54f66881f8f4 Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 6 Aug 2021 17:44:48 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A9=F0=9F=91=8C=20make=20lint=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin_bilibili/info.go | 1 + plugin_diana/bing.go | 6 +++- plugin_diana/text.go | 12 ++++--- plugin_github/repo_searcher.go | 3 +- plugin_image_finder/keyword.go | 6 ++-- plugin_minecraft/info.go | 4 +-- plugin_minecraft/manager.go | 4 +-- plugin_runcode/code_runner.go | 65 +++++++++++++++++----------------- plugin_setutime/setu_geter.go | 20 +++++------ plugin_setutime/sqlite.go | 2 +- 10 files changed, 66 insertions(+), 57 deletions(-) diff --git a/plugin_bilibili/info.go b/plugin_bilibili/info.go index 5741bd3f..84d39a18 100644 --- a/plugin_bilibili/info.go +++ b/plugin_bilibili/info.go @@ -1,3 +1,4 @@ +// Package bilibili 查询b站用户信息 package bilibili import ( diff --git a/plugin_diana/bing.go b/plugin_diana/bing.go index 001d1219..8ebc996d 100644 --- a/plugin_diana/bing.go +++ b/plugin_diana/bing.go @@ -2,6 +2,7 @@ package diana import ( + fmt "fmt" "math/rand" "time" @@ -71,6 +72,9 @@ func init() { // 增加小作文 zero.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission). Handle(func(ctx *zero.Ctx) { - addText(ctx.State["regex_matched"].([]string)[1]) + err := addText(ctx.State["regex_matched"].([]string)[1]) + if err != nil { + ctx.Send(fmt.Sprintf("ERROR: %v", err)) + } }) } diff --git a/plugin_diana/text.go b/plugin_diana/text.go index 32d087d7..f9ea7bc8 100644 --- a/plugin_diana/text.go +++ b/plugin_diana/text.go @@ -23,23 +23,27 @@ func init() { if err != nil { panic(err) } - loadText() - array = compo.Array + if loadText() == nil { + array = compo.Array + } }() } -func loadText() { +func loadText() error { if _, err := os.Stat(pbfile); err == nil || os.IsExist(err) { f, err := os.Open(pbfile) if err == nil { data, err1 := io.ReadAll(f) if err1 == nil { if len(data) > 0 { - compo.Unmarshal(data) + return compo.Unmarshal(data) } } + return err1 } + return err } + return nil } func addText(txt string) error { diff --git a/plugin_github/repo_searcher.go b/plugin_github/repo_searcher.go index dc5a006d..a119a8c8 100644 --- a/plugin_github/repo_searcher.go +++ b/plugin_github/repo_searcher.go @@ -2,6 +2,7 @@ package github import ( + "errors" "fmt" "io/ioutil" "net/http" @@ -90,7 +91,7 @@ func netGet(dest string, header http.Header) ([]byte, error) { } if code := resp.StatusCode; code != 200 { // 如果返回不是200则立刻抛出错误 - return nil, fmt.Errorf("code %d", code) + return nil, errors.New(fmt.Sprintf("code %d", code)) } return body, nil } diff --git a/plugin_image_finder/keyword.go b/plugin_image_finder/keyword.go index 15f7d572..4e49eefd 100644 --- a/plugin_image_finder/keyword.go +++ b/plugin_image_finder/keyword.go @@ -63,7 +63,7 @@ func init() { keyword := ctx.State["regex_matched"].([]string)[1] soutujson := soutuapi(keyword) pom1 := "https://i.pixiv.cat" - rannum := rand_int() + rannum := randint() pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:] ctx.SendChain(message.Image(pom1 + pom2)) }) @@ -97,8 +97,8 @@ func soutuapi(keyword string) *resultjson { return result } -// rand_int 从json里的30条数据中随机获取一条返回 -func rand_int() int { +// randint 从json里的30条数据中随机获取一条返回 +func randint() int { rand.Seed(time.Now().UnixNano()) return rand.Intn(30) } diff --git a/plugin_minecraft/info.go b/plugin_minecraft/info.go index d7c3fc79..841f4ed0 100644 --- a/plugin_minecraft/info.go +++ b/plugin_minecraft/info.go @@ -42,7 +42,7 @@ func init() { // 支持多个服务器 switch ctx.State["regex_matched"].([]string)[1] { case "ftbi": // 这里对应触发指令里的服务器名称 - ftbijson := infoapi("115.28.186.22:25710") //这里填对应mc服务器的登录地址 + ftbijson := infoapi("115.28.186.22:25710") // 这里填对应mc服务器的登录地址 var str = ftbijson.Players.List cs := strings.Join(str, "\n") ctx.SendChain(message.Text( @@ -51,7 +51,7 @@ func init() { "以下为玩家名字: ", "\n", cs, )) case "ges": // 这里对应触发指令里的服务器名称 - gesjson := infoapi("115.28.186.22:25701") //这里填对应mc服务器的登录地址 + gesjson := infoapi("115.28.186.22:25701") // 这里填对应mc服务器的登录地址 var str = gesjson.Players.List cs := strings.Join(str, "\n") ctx.SendChain(message.Text( diff --git a/plugin_minecraft/manager.go b/plugin_minecraft/manager.go index c64bf317..b82c01da 100644 --- a/plugin_minecraft/manager.go +++ b/plugin_minecraft/manager.go @@ -33,7 +33,7 @@ func init() { }) } -//开启服务器的api请求 +// 开启服务器的api请求 func start(name string) string { url := fmt.Sprintf("http://your.addr:23333/api/start_server/%s/?apikey=apikey", name) client := &http.Client{} @@ -54,7 +54,7 @@ func start(name string) string { return string(body) } -//关闭服务器的api请求 +// 关闭服务器的api请求 func stop(name string) string { url := fmt.Sprintf("http://your.addr:23333/api/stop_server/%s/?apikey=apikey", name) client := &http.Client{} diff --git a/plugin_runcode/code_runner.go b/plugin_runcode/code_runner.go index 82d99dec..f6cad44a 100644 --- a/plugin_runcode/code_runner.go +++ b/plugin_runcode/code_runner.go @@ -130,50 +130,49 @@ func init() { Handle(func(ctx *zero.Ctx) { if !limit.Load(ctx.Event.UserID).Acquire() { ctx.Send("请稍后重试0x0...") - return - } - language := ctx.State["regex_matched"].([]string)[1] - language = strings.ToLower(language) - if runType, exist := table[language]; !exist { - // 不支持语言 - ctx.SendChain( - message.Text("> ", ctx.Event.Sender.NickName, "\n"), - message.Text("语言不是受支持的编程语种呢~"), - ) - return } else { - if RunAllow == false { - // 运行代码被禁用 + language := ctx.State["regex_matched"].([]string)[1] + language = strings.ToLower(language) + if runType, exist := table[language]; !exist { + // 不支持语言 ctx.SendChain( message.Text("> ", ctx.Event.Sender.NickName, "\n"), - message.Text("在线运行代码功能已被禁用"), + message.Text("语言不是受支持的编程语种呢~"), ) } else { - // 执行运行 - block := ctx.State["regex_matched"].([]string)[2] - block = message.UnescapeCQCodeText(block) - if block == "help" { - // 输出模板 + if RunAllow == false { + // 运行代码被禁用 ctx.SendChain( - message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"), - message.Text( - ">runcode ", language, "\n", - templates[language], - ), + message.Text("> ", ctx.Event.Sender.NickName, "\n"), + message.Text("在线运行代码功能已被禁用"), ) } else { - if output, err := runCode(block, runType); err != nil { - // 运行失败 + // 执行运行 + block := ctx.State["regex_matched"].([]string)[2] + block = message.UnescapeCQCodeText(block) + if block == "help" { + // 输出模板 ctx.SendChain( - message.Text("> ", ctx.Event.Sender.NickName, "\n"), - message.Text("ERROR: ", err), + message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"), + message.Text( + ">runcode ", language, "\n", + templates[language], + ), ) } else { - // 运行成功 - ctx.SendChain( - message.Text("> ", ctx.Event.Sender.NickName, "\n"), - message.Text(output), - ) + if output, err := runCode(block, runType); err != nil { + // 运行失败 + ctx.SendChain( + message.Text("> ", ctx.Event.Sender.NickName, "\n"), + message.Text("ERROR: ", err), + ) + } else { + // 运行成功 + ctx.SendChain( + message.Text("> ", ctx.Event.Sender.NickName, "\n"), + message.Text(output), + ) + } } } } diff --git a/plugin_setutime/setu_geter.go b/plugin_setutime/setu_geter.go index 030f449f..fe899e21 100644 --- a/plugin_setutime/setu_geter.go +++ b/plugin_setutime/setu_geter.go @@ -193,31 +193,31 @@ func min(a, b int) int { } // size 返回缓冲池指定类型的现有大小 -func (p *imgpool) size(type_ string) int { - return len(p.Pool[type_]) +func (p *imgpool) size(imgtype string) int { + return len(p.Pool[imgtype]) } // isFull 返回缓冲池指定类型是否已满 -func (p *imgpool) isFull(type_ string) bool { - return len(p.Pool[type_]) >= p.Max +func (p *imgpool) isFull(imgtype_ string) bool { + return len(p.Pool[imgtype_]) >= p.Max } // push 向缓冲池插入一张图片 -func (p *imgpool) push(type_ string, illust *pixiv.Illust) { +func (p *imgpool) push(imgtype_ string, illust *pixiv.Illust) { p.Lock.Lock() defer p.Lock.Unlock() - p.Pool[type_] = append(p.Pool[type_], illust) + p.Pool[imgtype_] = append(p.Pool[imgtype_], illust) } // Push 在缓冲池拿出一张图片 -func (p *imgpool) pop(type_ string) (illust *pixiv.Illust) { +func (p *imgpool) pop(imgtype_ string) (illust *pixiv.Illust) { p.Lock.Lock() defer p.Lock.Unlock() - if p.size(type_) == 0 { + if p.size(imgtype_) == 0 { return } - illust = p.Pool[type_][0] - p.Pool[type_] = p.Pool[type_][1:] + illust = p.Pool[imgtype_][0] + p.Pool[imgtype_] = p.Pool[imgtype_][1:] return } diff --git a/plugin_setutime/sqlite.go b/plugin_setutime/sqlite.go index 06222df3..cd6961c8 100644 --- a/plugin_setutime/sqlite.go +++ b/plugin_setutime/sqlite.go @@ -5,7 +5,7 @@ import ( "reflect" "strings" - _ "modernc.org/sqlite" + _ "modernc.org/sqlite" // 引入sqlite ) // sqlite 数据库对象