mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
💩👌 make lint happy
This commit is contained in:
parent
e477e0b452
commit
ce406d8f55
@ -1,3 +1,4 @@
|
|||||||
|
// Package bilibili 查询b站用户信息
|
||||||
package bilibili
|
package bilibili
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@ -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))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite" // 引入sqlite
|
||||||
)
|
)
|
||||||
|
|
||||||
// sqlite 数据库对象
|
// sqlite 数据库对象
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user