💩👌 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).
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))]))
})
// 逆天

View File

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

View File

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

View File

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

View File

@ -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:
//
}
@ -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 + ",就是你啦!")
}
})
// 入群欢迎

View File

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

View File

@ -148,12 +148,10 @@ func init() {
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("在线运行代码功能已被禁用"),
)
return
}
} else {
// 执行运行
block := ctx.State["regex_matched"].([]string)[2]
block = message.UnescapeCQCodeText(block)
if block == "help" {
// 输出模板
ctx.SendChain(
@ -163,23 +161,21 @@ func init() {
templates[language],
),
)
return
}
} else {
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
}
}
}
}
})

View File

@ -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,7 +104,7 @@ 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]
imgtype = ctx.State["regex_matched"].([]string)[1]
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
)
ctx.SendChain(message.Text("少女祈祷中......"))
@ -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]
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
}