💩👌 make lint happy

This commit is contained in:
fumiama 2021-08-06 18:03:03 +08:00
parent ce406d8f55
commit bf78603d19
7 changed files with 40 additions and 44 deletions

View File

@ -44,7 +44,6 @@ func init() { // 插件主体
default: default:
// 频繁触发,不回复 // 频繁触发,不回复
} }
return
}) })
// 群空调 // 群空调
var AirConditTemp = map[int64]int{} var AirConditTemp = map[int64]int{}

View File

@ -28,7 +28,7 @@ type zhiwang struct {
// 小作文查重: 回复要查的消息 查重 // 小作文查重: 回复要查的消息 查重
func init() { func init() {
zero.OnMessage(fullMatchText("查重")). zero.OnMessage(fullmatch("查重")).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
msg := ctx.Event.Message msg := ctx.Event.Message
if msg[0].Type == "reply" { if msg[0].Type == "reply" {
@ -36,7 +36,7 @@ func init() {
msg := ctx.GetMessage(int64(id)).Elements[0].Data["text"] msg := ctx.GetMessage(int64(id)).Elements[0].Data["text"]
zhiwangjson := zhiwangapi(msg) zhiwangjson := zhiwangapi(msg)
if zhiwangjson.Code != 0 { if zhiwangjson == nil || zhiwangjson.Code != 0 {
ctx.Send("api返回错误") ctx.Send("api返回错误")
return return
} }
@ -60,8 +60,6 @@ func init() {
"查重结果仅作参考,请注意辨别是否为原创", "\n", "查重结果仅作参考,请注意辨别是否为原创", "\n",
"数据来源: https://asoulcnki.asia/", "数据来源: https://asoulcnki.asia/",
)) ))
} else {
return
} }
}) })
} }
@ -73,24 +71,25 @@ func zhiwangapi(Text string) *zhiwang {
post := "{\n\"text\":\"" + Text + "\"\n}" post := "{\n\"text\":\"" + Text + "\"\n}"
var jsonStr = []byte(post) var jsonStr = []byte(post)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
panic(err) return nil
} }
defer resp.Body.Close() defer resp.Body.Close()
result := &zhiwang{} result := &zhiwang{}
if err := json.NewDecoder(resp.Body).Decode(result); err != nil { if err1 := json.NewDecoder(resp.Body).Decode(result); err1 != nil {
panic(err) return nil
} }
return result return result
} }
func fullMatchText(src ...string) zero.Rule { func fullmatch(src ...string) zero.Rule {
return func(ctx *zero.Ctx) bool { return func(ctx *zero.Ctx) bool {
msg := ctx.Event.Message msg := ctx.Event.Message
for _, elem := range msg { for _, elem := range msg {

View File

@ -149,9 +149,9 @@ func init() { // 插件主体
case "分钟": case "分钟":
// //
case "小时": case "小时":
duration = duration * 60 duration *= 60
case "天": case "天":
duration = duration * 60 * 24 duration *= 60 * 24
default: default:
// //
} }

View File

@ -37,7 +37,6 @@ func init() {
default: // 默认 QQ音乐 default: // 默认 QQ音乐
ctx.SendChain(qqmusic(ctx.State["regex_matched"].([]string)[2])) ctx.SendChain(qqmusic(ctx.State["regex_matched"].([]string)[2]))
} }
return
}) })
} }

View File

@ -16,12 +16,10 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
var limit = rate.NewManager(time.Minute*3, 5) var (
enable = true
func init() { limit = rate.NewManager(time.Minute*3, 5)
RunAllow := true templates = map[string]string{
templates := map[string]string{
"py2": "print 'Hello World!'", "py2": "print 'Hello World!'",
"ruby": "puts \"Hello World!\";", "ruby": "puts \"Hello World!\";",
"rb": "puts \"Hello World!\";", "rb": "puts \"Hello World!\";",
@ -56,8 +54,7 @@ func init() {
"typescript": "const hello : string = \"Hello World!\"\nconsole.log(hello)", "typescript": "const hello : string = \"Hello World!\"\nconsole.log(hello)",
"ts": "const hello : string = \"Hello World!\"\nconsole.log(hello)", "ts": "const hello : string = \"Hello World!\"\nconsole.log(hello)",
} }
table = map[string][2]string{
table := map[string][2]string{
"py2": {"0", "py"}, "py2": {"0", "py"},
"ruby": {"1", "rb"}, "ruby": {"1", "rb"},
"rb": {"1", "rb"}, "rb": {"1", "rb"},
@ -92,7 +89,9 @@ func init() {
"typescript": {"1010", "ts"}, "typescript": {"1010", "ts"},
"ts": {"1010", "ts"}, "ts": {"1010", "ts"},
} }
)
func init() {
zero.OnFullMatch(">runcode help").SetBlock(true).FirstPriority(). zero.OnFullMatch(">runcode help").SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text( ctx.SendChain(message.Text(
@ -110,7 +109,7 @@ func init() {
zero.OnFullMatch(">runcode on", zero.AdminPermission).SetBlock(true).FirstPriority(). zero.OnFullMatch(">runcode on", zero.AdminPermission).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
RunAllow = true enable = true
ctx.SendChain( ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"), message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("在线运行代码功能已启用"), message.Text("在线运行代码功能已启用"),
@ -119,7 +118,7 @@ func init() {
zero.OnFullMatch(">runcode off", zero.AdminPermission).SetBlock(true).FirstPriority(). zero.OnFullMatch(">runcode off", zero.AdminPermission).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
RunAllow = false enable = false
ctx.SendChain( ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"), message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("在线运行代码功能已禁用"), message.Text("在线运行代码功能已禁用"),
@ -140,7 +139,7 @@ func init() {
message.Text("语言不是受支持的编程语种呢~"), message.Text("语言不是受支持的编程语种呢~"),
) )
} else { } else {
if RunAllow == false { if !enable {
// 运行代码被禁用 // 运行代码被禁用
ctx.SendChain( ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"), message.Text("> ", ctx.Event.Sender.NickName, "\n"),
@ -199,7 +198,7 @@ func runCode(code string, runType [2]string) (string, error) {
} }
// 发送请求 // 发送请求
client := &http.Client{ client := &http.Client{
Timeout: time.Duration(15 * time.Second), Timeout: 15 * time.Second,
} }
request, _ := http.NewRequest("POST", api, strings.NewReader(val.Encode())) request, _ := http.NewRequest("POST", api, strings.NewReader(val.Encode()))
request.Header = header request.Header = header

View File

@ -74,7 +74,7 @@ func init() { // 插件主体
continue continue
} }
// 下载图片 // 下载图片
if _, err := download(illust, pool.Path); err != nil { if err := download(illust, pool.Path); err != nil {
ctx.SendChain(message.Text("ERROR: ", err)) ctx.SendChain(message.Text("ERROR: ", err))
continue continue
} }
@ -98,7 +98,6 @@ func init() { // 插件主体
if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); 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
}) })
zero.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21). zero.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21).
@ -115,7 +114,7 @@ func init() { // 插件主体
return return
} }
// 下载插画 // 下载插画
if _, err := download(illust, pool.Path); err != nil { if err := download(illust, pool.Path); err != nil {
ctx.SendChain(message.Text("ERROR: ", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
@ -130,7 +129,6 @@ func init() { // 插件主体
return return
} }
ctx.Send("添加成功") ctx.Send("添加成功")
return
}) })
zero.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22). zero.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
@ -145,7 +143,6 @@ func init() { // 插件主体
return return
} }
ctx.Send("删除成功") ctx.Send("删除成功")
return
}) })
// 查询数据库涩图数量 // 查询数据库涩图数量
@ -163,7 +160,6 @@ func init() { // 插件主体
state = append(state, fmt.Sprintf("%d", num)) state = append(state, fmt.Sprintf("%d", num))
} }
ctx.Send(strings.Join(state, "")) ctx.Send(strings.Join(state, ""))
return
}) })
} }
@ -198,26 +194,26 @@ func (p *imgpool) size(imgtype string) int {
} }
// isFull 返回缓冲池指定类型是否已满 // isFull 返回缓冲池指定类型是否已满
func (p *imgpool) isFull(imgtype_ string) bool { func (p *imgpool) isFull(imgtype string) bool {
return len(p.Pool[imgtype_]) >= p.Max return len(p.Pool[imgtype]) >= p.Max
} }
// push 向缓冲池插入一张图片 // push 向缓冲池插入一张图片
func (p *imgpool) push(imgtype_ 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[imgtype_] = append(p.Pool[imgtype_], illust) p.Pool[imgtype] = append(p.Pool[imgtype], illust)
} }
// Push 在缓冲池拿出一张图片 // Push 在缓冲池拿出一张图片
func (p *imgpool) pop(imgtype_ 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(imgtype_) == 0 { if p.size(imgtype) == 0 {
return return
} }
illust = p.Pool[imgtype_][0] illust = p.Pool[imgtype][0]
p.Pool[imgtype_] = p.Pool[imgtype_][1:] p.Pool[imgtype] = p.Pool[imgtype][1:]
return return
} }
@ -237,17 +233,17 @@ func file(i *pixiv.Illust) string {
return "" return ""
} }
func download(i *pixiv.Illust, filedir string) (string, error) { func download(i *pixiv.Illust, filedir string) /*(string, */ error /*)*/ {
filename := fmt.Sprint(i.Pid) filename := fmt.Sprint(i.Pid)
filepath := filedir + filename filepath := filedir + filename
if _, err := os.Stat(filepath + ".jpg"); err == nil || os.IsExist(err) { if _, err := os.Stat(filepath + ".jpg"); err == nil || os.IsExist(err) {
return filepath + ".jpg", nil return /*filepath + ".jpg",*/ nil
} }
if _, err := os.Stat(filepath + ".png"); err == nil || os.IsExist(err) { if _, err := os.Stat(filepath + ".png"); err == nil || os.IsExist(err) {
return filepath + ".png", nil return /*filepath + ".png",*/ nil
} }
if _, err := os.Stat(filepath + ".gif"); err == nil || os.IsExist(err) { if _, err := os.Stat(filepath + ".gif"); err == nil || os.IsExist(err) {
return filepath + ".gif", nil return /*filepath + ".gif",*/ nil
} }
// 下载最大分辨率为 1200 的图片 // 下载最大分辨率为 1200 的图片
link := i.ImageUrls link := i.ImageUrls
@ -255,5 +251,6 @@ func download(i *pixiv.Illust, filedir string) (string, error) {
link = strings.ReplaceAll(link, "_p0", "_p0_master1200") link = strings.ReplaceAll(link, "_p0", "_p0_master1200")
link = strings.ReplaceAll(link, ".png", ".jpg") link = strings.ReplaceAll(link, ".png", ".jpg")
// 下载 // 下载
return pixiv.Download(link, filedir, filename) _, err1 := pixiv.Download(link, filedir, filename)
return err1
} }

View File

@ -61,6 +61,9 @@ func (db *sqlite) insert(table string, objptr interface{}) (err error) {
if err != nil { if err != nil {
return err return err
} }
if rows.Err() != nil {
return rows.Err()
}
tags, _ := rows.Columns() tags, _ := rows.Columns()
rows.Close() rows.Close()
var ( var (