diff --git a/plugin_diana/bing.go b/plugin_diana/bing.go index 4a675d79..001d1219 100644 --- a/plugin_diana/bing.go +++ b/plugin_diana/bing.go @@ -60,7 +60,7 @@ func init() { zero.OnFullMatch("小作文", zero.OnlyToMe). Handle(func(ctx *zero.Ctx) { rand.Seed(time.Now().UnixNano()) - ctx.SendChain(message.Text(ARRAY[rand.Intn(len(ARRAY))])) + ctx.SendChain(message.Text(array[rand.Intn(len(array))])) }) // 逆天 diff --git a/plugin_diana/text.go b/plugin_diana/text.go index c9cd2ac7..32d087d7 100644 --- a/plugin_diana/text.go +++ b/plugin_diana/text.go @@ -13,7 +13,7 @@ const ( var ( compo Composition - ARRAY []string + array []string ) func init() { @@ -24,7 +24,7 @@ func init() { panic(err) } loadText() - ARRAY = compo.Array + array = compo.Array }() } @@ -44,18 +44,17 @@ func loadText() { func addText(txt string) error { if txt != "" { - ARRAY = append(ARRAY, txt) + array = append(array, txt) data, err := compo.Marshal() if err == nil { if _, err := os.Stat(datapath); err == nil || os.IsExist(err) { f, err1 := os.OpenFile(pbfile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) - if err1 != nil { - return err1 - } else { + if err1 == nil { defer f.Close() _, err2 := f.Write(data) return err2 } + return err1 } } return err diff --git a/plugin_github/repo_searcher.go b/plugin_github/repo_searcher.go index 34101beb..dc5a006d 100644 --- a/plugin_github/repo_searcher.go +++ b/plugin_github/repo_searcher.go @@ -1,8 +1,7 @@ -// Plugin github GitHub 仓库搜索 +// Package github GitHub 仓库搜索 package github import ( - "errors" "fmt" "io/ioutil" "net/http" @@ -64,9 +63,9 @@ func init() { // 插件主体 } // notnull 如果传入文本为空,则返回默认值 -func notnull(text, default_ string) string { +func notnull(text, defstr string) string { if text == "" { - return default_ + return defstr } return text } @@ -91,7 +90,7 @@ func netGet(dest string, header http.Header) ([]byte, error) { } if code := resp.StatusCode; code != 200 { // 如果返回不是200则立刻抛出错误 - return nil, errors.New(fmt.Sprintf("code %d", code)) + return nil, fmt.Errorf("code %d", code) } return body, nil } diff --git a/plugin_lolicon/lolicon.go b/plugin_lolicon/lolicon.go index f1fc20ef..dd68dcdd 100644 --- a/plugin_lolicon/lolicon.go +++ b/plugin_lolicon/lolicon.go @@ -58,7 +58,6 @@ func init() { func min(a, b int) int { if a < b { return a - } else { - return b } + return b } diff --git a/plugin_manager/manager.go b/plugin_manager/manager.go index 30ac8cfc..dae56bb5 100644 --- a/plugin_manager/manager.go +++ b/plugin_manager/manager.go @@ -1,3 +1,4 @@ +// Package manager 群管 package manager import ( @@ -114,9 +115,9 @@ func init() { // 插件主体 case "分钟": // case "小时": - duration = duration * 60 + duration *= 60 case "天": - duration = duration * 60 * 24 + duration *= 60 * 24 default: // } @@ -246,7 +247,7 @@ func init() { // 插件主体 t, ok := (*timer.Timers)[ti] if ok { t.Enable = false - delete(*timer.Timers, ti) //避免重复取消 + delete(*timer.Timers, ti) // 避免重复取消 _ = timer.SaveTimers() ctx.Send("取消成功~") } else { @@ -254,7 +255,7 @@ func init() { // 插件主体 } } }) - //列出本群所有定时 + // 列出本群所有定时 zero.OnFullMatch("列出所有提醒", zero.SuperUserPermission).SetBlock(true).SetPriority(40). Handle(func(ctx *zero.Ctx) { if ctx.Event.GroupID > 0 { @@ -267,12 +268,12 @@ func init() { // 插件主体 if ctx.Event.GroupID > 0 { list := ctx.GetGroupMemberList(ctx.Event.GroupID) rand.Seed(time.Now().UnixNano()) - rand_index := fmt.Sprint(rand.Intn(int(list.Get("#").Int()))) - random_card := list.Get(rand_index + ".card").String() - if random_card == "" { - random_card = list.Get(rand_index + ".nickname").String() + randIndex := fmt.Sprint(rand.Intn(int(list.Get("#").Int()))) + randCard := list.Get(randIndex + ".card").String() + if randCard == "" { + randCard = list.Get(randIndex + ".nickname").String() } - ctx.Send(random_card + ",就是你啦!") + ctx.Send(randCard + ",就是你啦!") } }) // 入群欢迎 diff --git a/plugin_music/selecter.go b/plugin_music/selecter.go index 4fde2240..7927fd71 100644 --- a/plugin_music/selecter.go +++ b/plugin_music/selecter.go @@ -219,9 +219,9 @@ func md5str(s string) string { } // netGet 返回请求数据 -func netGet(get_url string, header http.Header) []byte { +func netGet(url string, header http.Header) []byte { client := &http.Client{} - request, _ := http.NewRequest("GET", get_url, nil) + request, _ := http.NewRequest("GET", url, nil) request.Header = header res, err := client.Do(request) if err != nil { @@ -233,9 +233,9 @@ func netGet(get_url string, header http.Header) []byte { } // netPost 返回请求数据 -func netPost(post_url string, data url.Values, header http.Header) []byte { +func netPost(url string, data url.Values, header http.Header) []byte { client := &http.Client{} - request, _ := http.NewRequest("POST", post_url, strings.NewReader(data.Encode())) + request, _ := http.NewRequest("POST", url, strings.NewReader(data.Encode())) request.Header = header res, err := client.Do(request) if err != nil { diff --git a/plugin_runcode/code_runner.go b/plugin_runcode/code_runner.go index 422efb82..82d99dec 100644 --- a/plugin_runcode/code_runner.go +++ b/plugin_runcode/code_runner.go @@ -148,38 +148,34 @@ func init() { message.Text("> ", ctx.Event.Sender.NickName, "\n"), message.Text("在线运行代码功能已被禁用"), ) - return - } - // 执行运行 - block := ctx.State["regex_matched"].([]string)[2] - block = message.UnescapeCQCodeText(block) - - if block == "help" { - // 输出模板 - ctx.SendChain( - message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"), - message.Text( - ">runcode ", language, "\n", - templates[language], - ), - ) - return - } - - if output, err := runCode(block, runType); err != nil { - // 运行失败 - ctx.SendChain( - message.Text("> ", ctx.Event.Sender.NickName, "\n"), - message.Text("ERROR: ", err), - ) - return } else { - // 运行成功 - ctx.SendChain( - message.Text("> ", ctx.Event.Sender.NickName, "\n"), - message.Text(output), - ) - return + // 执行运行 + block := ctx.State["regex_matched"].([]string)[2] + block = message.UnescapeCQCodeText(block) + if block == "help" { + // 输出模板 + ctx.SendChain( + message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"), + message.Text( + ">runcode ", language, "\n", + templates[language], + ), + ) + } else { + 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 116e7267..030f449f 100644 --- a/plugin_setutime/setu_geter.go +++ b/plugin_setutime/setu_geter.go @@ -62,14 +62,14 @@ func init() { // 插件主体 ctx.SendChain(message.Text("请稍后重试0x0...")) return } - var type_ = ctx.State["regex_matched"].([]string)[1] + var imgtype = ctx.State["regex_matched"].([]string)[1] // 补充池子 go func() { - times := min(pool.Max-pool.size(type_), 2) + times := min(pool.Max-pool.size(imgtype), 2) for i := 0; i < times; i++ { illust := &pixiv.Illust{} // 查询出一张图片 - if err := pool.DB.find(type_, illust, "ORDER BY RANDOM() limit 1"); err != nil { + if err := pool.DB.find(imgtype, illust, "ORDER BY RANDOM() limit 1"); err != nil { ctx.SendChain(message.Text("ERROR: ", err)) continue } @@ -80,22 +80,22 @@ func init() { // 插件主体 } ctx.SendGroupMessage(pool.Group, []message.MessageSegment{message.Image(file(illust))}) // 向缓冲池添加一张图片 - pool.push(type_, illust) + pool.push(imgtype, illust) time.Sleep(time.Second * 1) } }() // 如果没有缓存,阻塞5秒 - if pool.size(type_) == 0 { + if pool.size(imgtype) == 0 { ctx.SendChain(message.Text("INFO: 正在填充弹药......")) <-time.After(time.Second * 5) - if pool.size(type_) == 0 { + if pool.size(imgtype) == 0 { ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......")) return } } // 从缓冲池里抽一张 - if id := ctx.SendChain(message.Image(file(pool.pop(type_)))); id == 0 { + if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); id == 0 { ctx.SendChain(message.Text("ERROR: 可能被风控了")) } return @@ -104,8 +104,8 @@ func init() { // 插件主体 zero.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21). Handle(func(ctx *zero.Ctx) { var ( - type_ = ctx.State["regex_matched"].([]string)[1] - id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) + imgtype = ctx.State["regex_matched"].([]string)[1] + id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) ) ctx.SendChain(message.Text("少女祈祷中......")) // 查询P站插图信息 @@ -125,7 +125,7 @@ func init() { // 插件主体 return } // 添加插画到对应的数据库table - if err := pool.DB.insert(type_, illust); err != nil { + if err := pool.DB.insert(imgtype, illust); err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return } @@ -136,11 +136,11 @@ func init() { // 插件主体 zero.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22). Handle(func(ctx *zero.Ctx) { var ( - type_ = ctx.State["regex_matched"].([]string)[1] - id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) + imgtype = ctx.State["regex_matched"].([]string)[1] + id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) ) // 查询数据库 - if err := pool.DB.del(type_, fmt.Sprintf("WHERE pid=%d", id)); err != nil { + if err := pool.DB.del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil { ctx.Send(fmt.Sprintf("ERROR: %v", err)) return }