💩👌 make lint happy

This commit is contained in:
fumiama 2021-08-06 17:32:17 +08:00
parent 541c0d1bca
commit e477e0b452
8 changed files with 65 additions and 71 deletions

View File

@ -60,7 +60,7 @@ func init() {
zero.OnFullMatch("小作文", zero.OnlyToMe). zero.OnFullMatch("小作文", zero.OnlyToMe).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
ctx.SendChain(message.Text(ARRAY[rand.Intn(len(ARRAY))])) ctx.SendChain(message.Text(array[rand.Intn(len(array))]))
}) })
// 逆天 // 逆天

View File

@ -13,7 +13,7 @@ const (
var ( var (
compo Composition compo Composition
ARRAY []string array []string
) )
func init() { func init() {
@ -24,7 +24,7 @@ func init() {
panic(err) panic(err)
} }
loadText() loadText()
ARRAY = compo.Array array = compo.Array
}() }()
} }
@ -44,18 +44,17 @@ func loadText() {
func addText(txt string) error { func addText(txt string) error {
if txt != "" { if txt != "" {
ARRAY = append(ARRAY, txt) array = append(array, txt)
data, err := compo.Marshal() data, err := compo.Marshal()
if err == nil { if err == nil {
if _, err := os.Stat(datapath); err == nil || os.IsExist(err) { 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) f, err1 := os.OpenFile(pbfile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err1 != nil { if err1 == nil {
return err1
} else {
defer f.Close() defer f.Close()
_, err2 := f.Write(data) _, err2 := f.Write(data)
return err2 return err2
} }
return err1
} }
} }
return err return err

View File

@ -1,8 +1,7 @@
// Plugin github GitHub 仓库搜索 // Package github GitHub 仓库搜索
package github package github
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -64,9 +63,9 @@ func init() { // 插件主体
} }
// notnull 如果传入文本为空,则返回默认值 // notnull 如果传入文本为空,则返回默认值
func notnull(text, default_ string) string { func notnull(text, defstr string) string {
if text == "" { if text == "" {
return default_ return defstr
} }
return text return text
} }
@ -91,7 +90,7 @@ func netGet(dest string, header http.Header) ([]byte, error) {
} }
if code := resp.StatusCode; code != 200 { if code := resp.StatusCode; code != 200 {
// 如果返回不是200则立刻抛出错误 // 如果返回不是200则立刻抛出错误
return nil, errors.New(fmt.Sprintf("code %d", code)) return nil, fmt.Errorf("code %d", code)
} }
return body, nil return body, nil
} }

View File

@ -58,7 +58,6 @@ func init() {
func min(a, b int) int { func min(a, b int) int {
if a < b { if a < b {
return a return a
} else { }
return b return b
} }
}

View File

@ -1,3 +1,4 @@
// Package manager 群管
package manager package manager
import ( import (
@ -114,9 +115,9 @@ func init() { // 插件主体
case "分钟": case "分钟":
// //
case "小时": case "小时":
duration = duration * 60 duration *= 60
case "天": case "天":
duration = duration * 60 * 24 duration *= 60 * 24
default: default:
// //
} }
@ -267,12 +268,12 @@ func init() { // 插件主体
if ctx.Event.GroupID > 0 { if ctx.Event.GroupID > 0 {
list := ctx.GetGroupMemberList(ctx.Event.GroupID) list := ctx.GetGroupMemberList(ctx.Event.GroupID)
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
rand_index := fmt.Sprint(rand.Intn(int(list.Get("#").Int()))) randIndex := fmt.Sprint(rand.Intn(int(list.Get("#").Int())))
random_card := list.Get(rand_index + ".card").String() randCard := list.Get(randIndex + ".card").String()
if random_card == "" { if randCard == "" {
random_card = list.Get(rand_index + ".nickname").String() randCard = list.Get(randIndex + ".nickname").String()
} }
ctx.Send(random_card + ",就是你啦!") ctx.Send(randCard + ",就是你啦!")
} }
}) })
// 入群欢迎 // 入群欢迎

View File

@ -219,9 +219,9 @@ func md5str(s string) string {
} }
// netGet 返回请求数据 // netGet 返回请求数据
func netGet(get_url string, header http.Header) []byte { func netGet(url string, header http.Header) []byte {
client := &http.Client{} client := &http.Client{}
request, _ := http.NewRequest("GET", get_url, nil) request, _ := http.NewRequest("GET", url, nil)
request.Header = header request.Header = header
res, err := client.Do(request) res, err := client.Do(request)
if err != nil { if err != nil {
@ -233,9 +233,9 @@ func netGet(get_url string, header http.Header) []byte {
} }
// netPost 返回请求数据 // 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{} 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 request.Header = header
res, err := client.Do(request) res, err := client.Do(request)
if err != nil { if err != nil {

View File

@ -148,12 +148,10 @@ func init() {
message.Text("> ", ctx.Event.Sender.NickName, "\n"), message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("在线运行代码功能已被禁用"), message.Text("在线运行代码功能已被禁用"),
) )
return } else {
}
// 执行运行 // 执行运行
block := ctx.State["regex_matched"].([]string)[2] block := ctx.State["regex_matched"].([]string)[2]
block = message.UnescapeCQCodeText(block) block = message.UnescapeCQCodeText(block)
if block == "help" { if block == "help" {
// 输出模板 // 输出模板
ctx.SendChain( ctx.SendChain(
@ -163,23 +161,21 @@ func init() {
templates[language], templates[language],
), ),
) )
return } else {
}
if output, err := runCode(block, runType); err != nil { if output, err := runCode(block, runType); err != nil {
// 运行失败 // 运行失败
ctx.SendChain( ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"), message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("ERROR: ", err), message.Text("ERROR: ", err),
) )
return
} else { } else {
// 运行成功 // 运行成功
ctx.SendChain( ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"), message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text(output), message.Text(output),
) )
return }
}
} }
} }
}) })

View File

@ -62,14 +62,14 @@ func init() { // 插件主体
ctx.SendChain(message.Text("请稍后重试0x0...")) ctx.SendChain(message.Text("请稍后重试0x0..."))
return return
} }
var type_ = ctx.State["regex_matched"].([]string)[1] var imgtype = ctx.State["regex_matched"].([]string)[1]
// 补充池子 // 补充池子
go func() { go func() {
times := min(pool.Max-pool.size(type_), 2) times := min(pool.Max-pool.size(imgtype), 2)
for i := 0; i < times; i++ { for i := 0; i < times; i++ {
illust := &pixiv.Illust{} 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)) ctx.SendChain(message.Text("ERROR: ", err))
continue continue
} }
@ -80,22 +80,22 @@ func init() { // 插件主体
} }
ctx.SendGroupMessage(pool.Group, []message.MessageSegment{message.Image(file(illust))}) ctx.SendGroupMessage(pool.Group, []message.MessageSegment{message.Image(file(illust))})
// 向缓冲池添加一张图片 // 向缓冲池添加一张图片
pool.push(type_, illust) pool.push(imgtype, illust)
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
} }
}() }()
// 如果没有缓存阻塞5秒 // 如果没有缓存阻塞5秒
if pool.size(type_) == 0 { if pool.size(imgtype) == 0 {
ctx.SendChain(message.Text("INFO: 正在填充弹药......")) ctx.SendChain(message.Text("INFO: 正在填充弹药......"))
<-time.After(time.Second * 5) <-time.After(time.Second * 5)
if pool.size(type_) == 0 { if pool.size(imgtype) == 0 {
ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......")) ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......"))
return 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: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
return return
@ -104,7 +104,7 @@ func init() { // 插件主体
zero.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21). zero.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
var ( var (
type_ = ctx.State["regex_matched"].([]string)[1] imgtype = ctx.State["regex_matched"].([]string)[1]
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
) )
ctx.SendChain(message.Text("少女祈祷中......")) ctx.SendChain(message.Text("少女祈祷中......"))
@ -125,7 +125,7 @@ func init() { // 插件主体
return return
} }
// 添加插画到对应的数据库table // 添加插画到对应的数据库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)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
@ -136,11 +136,11 @@ func init() { // 插件主体
zero.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22). zero.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
var ( var (
type_ = ctx.State["regex_matched"].([]string)[1] imgtype = ctx.State["regex_matched"].([]string)[1]
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) 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)) ctx.Send(fmt.Sprintf("ERROR: %v", err))
return return
} }