💩👌 make lint happy

This commit is contained in:
fumiama 2021-08-06 17:44:48 +08:00
parent e477e0b452
commit ce406d8f55
10 changed files with 66 additions and 57 deletions

View File

@ -1,3 +1,4 @@
// Package bilibili 查询b站用户信息
package bilibili
import (

View File

@ -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))
}
})
}

View File

@ -23,23 +23,27 @@ func init() {
if err != nil {
panic(err)
}
loadText()
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 {

View File

@ -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
}

View File

@ -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)
}

View File

@ -130,8 +130,7 @@ func init() {
Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.UserID).Acquire() {
ctx.Send("请稍后重试0x0...")
return
}
} else {
language := ctx.State["regex_matched"].([]string)[1]
language = strings.ToLower(language)
if runType, exist := table[language]; !exist {
@ -140,7 +139,6 @@ func init() {
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("语言不是受支持的编程语种呢~"),
)
return
} else {
if RunAllow == false {
// 运行代码被禁用
@ -178,6 +176,7 @@ func init() {
}
}
}
}
})
}

View File

@ -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
}

View File

@ -5,7 +5,7 @@ import (
"reflect"
"strings"
_ "modernc.org/sqlite"
_ "modernc.org/sqlite" // 引入sqlite
)
// sqlite 数据库对象