mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
💩👌 make lint happy
This commit is contained in:
parent
ce406d8f55
commit
bf78603d19
@ -44,7 +44,6 @@ func init() { // 插件主体
|
||||
default:
|
||||
// 频繁触发,不回复
|
||||
}
|
||||
return
|
||||
})
|
||||
// 群空调
|
||||
var AirConditTemp = map[int64]int{}
|
||||
|
||||
@ -28,7 +28,7 @@ type zhiwang struct {
|
||||
|
||||
// 小作文查重: 回复要查的消息 查重
|
||||
func init() {
|
||||
zero.OnMessage(fullMatchText("查重")).
|
||||
zero.OnMessage(fullmatch("查重")).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
msg := ctx.Event.Message
|
||||
if msg[0].Type == "reply" {
|
||||
@ -36,7 +36,7 @@ func init() {
|
||||
msg := ctx.GetMessage(int64(id)).Elements[0].Data["text"]
|
||||
zhiwangjson := zhiwangapi(msg)
|
||||
|
||||
if zhiwangjson.Code != 0 {
|
||||
if zhiwangjson == nil || zhiwangjson.Code != 0 {
|
||||
ctx.Send("api返回错误")
|
||||
return
|
||||
}
|
||||
@ -60,8 +60,6 @@ func init() {
|
||||
"查重结果仅作参考,请注意辨别是否为原创", "\n",
|
||||
"数据来源: https://asoulcnki.asia/",
|
||||
))
|
||||
} else {
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -73,24 +71,25 @@ func zhiwangapi(Text string) *zhiwang {
|
||||
post := "{\n\"text\":\"" + Text + "\"\n}"
|
||||
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")
|
||||
client := &http.Client{}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
result := &zhiwang{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(result); err != nil {
|
||||
panic(err)
|
||||
if err1 := json.NewDecoder(resp.Body).Decode(result); err1 != nil {
|
||||
return nil
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func fullMatchText(src ...string) zero.Rule {
|
||||
func fullmatch(src ...string) zero.Rule {
|
||||
return func(ctx *zero.Ctx) bool {
|
||||
msg := ctx.Event.Message
|
||||
for _, elem := range msg {
|
||||
|
||||
@ -149,9 +149,9 @@ func init() { // 插件主体
|
||||
case "分钟":
|
||||
//
|
||||
case "小时":
|
||||
duration = duration * 60
|
||||
duration *= 60
|
||||
case "天":
|
||||
duration = duration * 60 * 24
|
||||
duration *= 60 * 24
|
||||
default:
|
||||
//
|
||||
}
|
||||
|
||||
@ -37,7 +37,6 @@ func init() {
|
||||
default: // 默认 QQ音乐
|
||||
ctx.SendChain(qqmusic(ctx.State["regex_matched"].([]string)[2]))
|
||||
}
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -16,12 +16,10 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
var limit = rate.NewManager(time.Minute*3, 5)
|
||||
|
||||
func init() {
|
||||
RunAllow := true
|
||||
|
||||
templates := map[string]string{
|
||||
var (
|
||||
enable = true
|
||||
limit = rate.NewManager(time.Minute*3, 5)
|
||||
templates = map[string]string{
|
||||
"py2": "print 'Hello World!'",
|
||||
"ruby": "puts \"Hello World!\";",
|
||||
"rb": "puts \"Hello World!\";",
|
||||
@ -56,8 +54,7 @@ func init() {
|
||||
"typescript": "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"},
|
||||
"ruby": {"1", "rb"},
|
||||
"rb": {"1", "rb"},
|
||||
@ -92,7 +89,9 @@ func init() {
|
||||
"typescript": {"1010", "ts"},
|
||||
"ts": {"1010", "ts"},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
zero.OnFullMatch(">runcode help").SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SendChain(message.Text(
|
||||
@ -110,7 +109,7 @@ func init() {
|
||||
|
||||
zero.OnFullMatch(">runcode on", zero.AdminPermission).SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
RunAllow = true
|
||||
enable = true
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text("在线运行代码功能已启用"),
|
||||
@ -119,7 +118,7 @@ func init() {
|
||||
|
||||
zero.OnFullMatch(">runcode off", zero.AdminPermission).SetBlock(true).FirstPriority().
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
RunAllow = false
|
||||
enable = false
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
message.Text("在线运行代码功能已禁用"),
|
||||
@ -140,7 +139,7 @@ func init() {
|
||||
message.Text("语言不是受支持的编程语种呢~"),
|
||||
)
|
||||
} else {
|
||||
if RunAllow == false {
|
||||
if !enable {
|
||||
// 运行代码被禁用
|
||||
ctx.SendChain(
|
||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||
@ -199,7 +198,7 @@ func runCode(code string, runType [2]string) (string, error) {
|
||||
}
|
||||
// 发送请求
|
||||
client := &http.Client{
|
||||
Timeout: time.Duration(15 * time.Second),
|
||||
Timeout: 15 * time.Second,
|
||||
}
|
||||
request, _ := http.NewRequest("POST", api, strings.NewReader(val.Encode()))
|
||||
request.Header = header
|
||||
|
||||
@ -74,7 +74,7 @@ func init() { // 插件主体
|
||||
continue
|
||||
}
|
||||
// 下载图片
|
||||
if _, err := download(illust, pool.Path); err != nil {
|
||||
if err := download(illust, pool.Path); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
continue
|
||||
}
|
||||
@ -98,7 +98,6 @@ func init() { // 插件主体
|
||||
if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); id == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
|
||||
}
|
||||
return
|
||||
})
|
||||
|
||||
zero.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21).
|
||||
@ -115,7 +114,7 @@ func init() { // 插件主体
|
||||
return
|
||||
}
|
||||
// 下载插画
|
||||
if _, err := download(illust, pool.Path); err != nil {
|
||||
if err := download(illust, pool.Path); err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
@ -130,7 +129,6 @@ func init() { // 插件主体
|
||||
return
|
||||
}
|
||||
ctx.Send("添加成功")
|
||||
return
|
||||
})
|
||||
|
||||
zero.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
|
||||
@ -145,7 +143,6 @@ func init() { // 插件主体
|
||||
return
|
||||
}
|
||||
ctx.Send("删除成功")
|
||||
return
|
||||
})
|
||||
|
||||
// 查询数据库涩图数量
|
||||
@ -163,7 +160,6 @@ func init() { // 插件主体
|
||||
state = append(state, fmt.Sprintf("%d", num))
|
||||
}
|
||||
ctx.Send(strings.Join(state, ""))
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
@ -198,26 +194,26 @@ func (p *imgpool) size(imgtype string) int {
|
||||
}
|
||||
|
||||
// isFull 返回缓冲池指定类型是否已满
|
||||
func (p *imgpool) isFull(imgtype_ string) bool {
|
||||
return len(p.Pool[imgtype_]) >= p.Max
|
||||
func (p *imgpool) isFull(imgtype string) bool {
|
||||
return len(p.Pool[imgtype]) >= p.Max
|
||||
}
|
||||
|
||||
// push 向缓冲池插入一张图片
|
||||
func (p *imgpool) push(imgtype_ string, illust *pixiv.Illust) {
|
||||
func (p *imgpool) push(imgtype string, illust *pixiv.Illust) {
|
||||
p.Lock.Lock()
|
||||
defer p.Lock.Unlock()
|
||||
p.Pool[imgtype_] = append(p.Pool[imgtype_], illust)
|
||||
p.Pool[imgtype] = append(p.Pool[imgtype], illust)
|
||||
}
|
||||
|
||||
// Push 在缓冲池拿出一张图片
|
||||
func (p *imgpool) pop(imgtype_ string) (illust *pixiv.Illust) {
|
||||
func (p *imgpool) pop(imgtype string) (illust *pixiv.Illust) {
|
||||
p.Lock.Lock()
|
||||
defer p.Lock.Unlock()
|
||||
if p.size(imgtype_) == 0 {
|
||||
if p.size(imgtype) == 0 {
|
||||
return
|
||||
}
|
||||
illust = p.Pool[imgtype_][0]
|
||||
p.Pool[imgtype_] = p.Pool[imgtype_][1:]
|
||||
illust = p.Pool[imgtype][0]
|
||||
p.Pool[imgtype] = p.Pool[imgtype][1:]
|
||||
return
|
||||
}
|
||||
|
||||
@ -237,17 +233,17 @@ func file(i *pixiv.Illust) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func download(i *pixiv.Illust, filedir string) (string, error) {
|
||||
func download(i *pixiv.Illust, filedir string) /*(string, */ error /*)*/ {
|
||||
filename := fmt.Sprint(i.Pid)
|
||||
filepath := filedir + filename
|
||||
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) {
|
||||
return filepath + ".png", nil
|
||||
return /*filepath + ".png",*/ nil
|
||||
}
|
||||
if _, err := os.Stat(filepath + ".gif"); err == nil || os.IsExist(err) {
|
||||
return filepath + ".gif", nil
|
||||
return /*filepath + ".gif",*/ nil
|
||||
}
|
||||
// 下载最大分辨率为 1200 的图片
|
||||
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, ".png", ".jpg")
|
||||
// 下载
|
||||
return pixiv.Download(link, filedir, filename)
|
||||
_, err1 := pixiv.Download(link, filedir, filename)
|
||||
return err1
|
||||
}
|
||||
|
||||
@ -61,6 +61,9 @@ func (db *sqlite) insert(table string, objptr interface{}) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return rows.Err()
|
||||
}
|
||||
tags, _ := rows.Columns()
|
||||
rows.Close()
|
||||
var (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user