💩👌 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 package bilibili
import ( import (

View File

@ -2,6 +2,7 @@
package diana package diana
import ( import (
fmt "fmt"
"math/rand" "math/rand"
"time" "time"
@ -71,6 +72,9 @@ func init() {
// 增加小作文 // 增加小作文
zero.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission). zero.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).
Handle(func(ctx *zero.Ctx) { 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 { if err != nil {
panic(err) panic(err)
} }
loadText() if loadText() == nil {
array = compo.Array array = compo.Array
}
}() }()
} }
func loadText() { func loadText() error {
if _, err := os.Stat(pbfile); err == nil || os.IsExist(err) { if _, err := os.Stat(pbfile); err == nil || os.IsExist(err) {
f, err := os.Open(pbfile) f, err := os.Open(pbfile)
if err == nil { if err == nil {
data, err1 := io.ReadAll(f) data, err1 := io.ReadAll(f)
if err1 == nil { if err1 == nil {
if len(data) > 0 { if len(data) > 0 {
compo.Unmarshal(data) return compo.Unmarshal(data)
} }
} }
return err1
} }
return err
} }
return nil
} }
func addText(txt string) error { func addText(txt string) error {

View File

@ -2,6 +2,7 @@
package github package github
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -90,7 +91,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, fmt.Errorf("code %d", code) return nil, errors.New(fmt.Sprintf("code %d", code))
} }
return body, nil return body, nil
} }

View File

@ -63,7 +63,7 @@ func init() {
keyword := ctx.State["regex_matched"].([]string)[1] keyword := ctx.State["regex_matched"].([]string)[1]
soutujson := soutuapi(keyword) soutujson := soutuapi(keyword)
pom1 := "https://i.pixiv.cat" pom1 := "https://i.pixiv.cat"
rannum := rand_int() rannum := randint()
pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:] pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:]
ctx.SendChain(message.Image(pom1 + pom2)) ctx.SendChain(message.Image(pom1 + pom2))
}) })
@ -97,8 +97,8 @@ func soutuapi(keyword string) *resultjson {
return result return result
} }
// rand_int 从json里的30条数据中随机获取一条返回 // randint 从json里的30条数据中随机获取一条返回
func rand_int() int { func randint() int {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
return rand.Intn(30) return rand.Intn(30)
} }

View File

@ -42,7 +42,7 @@ func init() {
// 支持多个服务器 // 支持多个服务器
switch ctx.State["regex_matched"].([]string)[1] { switch ctx.State["regex_matched"].([]string)[1] {
case "ftbi": // 这里对应触发指令里的服务器名称 case "ftbi": // 这里对应触发指令里的服务器名称
ftbijson := infoapi("115.28.186.22:25710") //这里填对应mc服务器的登录地址 ftbijson := infoapi("115.28.186.22:25710") // 这里填对应mc服务器的登录地址
var str = ftbijson.Players.List var str = ftbijson.Players.List
cs := strings.Join(str, "\n") cs := strings.Join(str, "\n")
ctx.SendChain(message.Text( ctx.SendChain(message.Text(
@ -51,7 +51,7 @@ func init() {
"以下为玩家名字: ", "\n", cs, "以下为玩家名字: ", "\n", cs,
)) ))
case "ges": // 这里对应触发指令里的服务器名称 case "ges": // 这里对应触发指令里的服务器名称
gesjson := infoapi("115.28.186.22:25701") //这里填对应mc服务器的登录地址 gesjson := infoapi("115.28.186.22:25701") // 这里填对应mc服务器的登录地址
var str = gesjson.Players.List var str = gesjson.Players.List
cs := strings.Join(str, "\n") cs := strings.Join(str, "\n")
ctx.SendChain(message.Text( ctx.SendChain(message.Text(

View File

@ -33,7 +33,7 @@ func init() {
}) })
} }
//开启服务器的api请求 // 开启服务器的api请求
func start(name string) string { func start(name string) string {
url := fmt.Sprintf("http://your.addr:23333/api/start_server/%s/?apikey=apikey", name) url := fmt.Sprintf("http://your.addr:23333/api/start_server/%s/?apikey=apikey", name)
client := &http.Client{} client := &http.Client{}
@ -54,7 +54,7 @@ func start(name string) string {
return string(body) return string(body)
} }
//关闭服务器的api请求 // 关闭服务器的api请求
func stop(name string) string { func stop(name string) string {
url := fmt.Sprintf("http://your.addr:23333/api/stop_server/%s/?apikey=apikey", name) url := fmt.Sprintf("http://your.addr:23333/api/stop_server/%s/?apikey=apikey", name)
client := &http.Client{} client := &http.Client{}

View File

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

View File

@ -193,31 +193,31 @@ func min(a, b int) int {
} }
// size 返回缓冲池指定类型的现有大小 // size 返回缓冲池指定类型的现有大小
func (p *imgpool) size(type_ string) int { func (p *imgpool) size(imgtype string) int {
return len(p.Pool[type_]) return len(p.Pool[imgtype])
} }
// isFull 返回缓冲池指定类型是否已满 // isFull 返回缓冲池指定类型是否已满
func (p *imgpool) isFull(type_ string) bool { func (p *imgpool) isFull(imgtype_ string) bool {
return len(p.Pool[type_]) >= p.Max return len(p.Pool[imgtype_]) >= p.Max
} }
// push 向缓冲池插入一张图片 // push 向缓冲池插入一张图片
func (p *imgpool) push(type_ string, illust *pixiv.Illust) { func (p *imgpool) push(imgtype_ string, illust *pixiv.Illust) {
p.Lock.Lock() p.Lock.Lock()
defer p.Lock.Unlock() defer p.Lock.Unlock()
p.Pool[type_] = append(p.Pool[type_], illust) p.Pool[imgtype_] = append(p.Pool[imgtype_], illust)
} }
// Push 在缓冲池拿出一张图片 // Push 在缓冲池拿出一张图片
func (p *imgpool) pop(type_ string) (illust *pixiv.Illust) { func (p *imgpool) pop(imgtype_ string) (illust *pixiv.Illust) {
p.Lock.Lock() p.Lock.Lock()
defer p.Lock.Unlock() defer p.Lock.Unlock()
if p.size(type_) == 0 { if p.size(imgtype_) == 0 {
return return
} }
illust = p.Pool[type_][0] illust = p.Pool[imgtype_][0]
p.Pool[type_] = p.Pool[type_][1:] p.Pool[imgtype_] = p.Pool[imgtype_][1:]
return return
} }

View File

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