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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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(
|
||||||
|
|||||||
@ -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{}
|
||||||
|
|||||||
@ -130,50 +130,49 @@ 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
|
|
||||||
}
|
|
||||||
language := ctx.State["regex_matched"].([]string)[1]
|
|
||||||
language = strings.ToLower(language)
|
|
||||||
if runType, exist := table[language]; !exist {
|
|
||||||
// 不支持语言
|
|
||||||
ctx.SendChain(
|
|
||||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
|
||||||
message.Text("语言不是受支持的编程语种呢~"),
|
|
||||||
)
|
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
if RunAllow == false {
|
language := ctx.State["regex_matched"].([]string)[1]
|
||||||
// 运行代码被禁用
|
language = strings.ToLower(language)
|
||||||
|
if runType, exist := table[language]; !exist {
|
||||||
|
// 不支持语言
|
||||||
ctx.SendChain(
|
ctx.SendChain(
|
||||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||||
message.Text("在线运行代码功能已被禁用"),
|
message.Text("语言不是受支持的编程语种呢~"),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// 执行运行
|
if RunAllow == false {
|
||||||
block := ctx.State["regex_matched"].([]string)[2]
|
// 运行代码被禁用
|
||||||
block = message.UnescapeCQCodeText(block)
|
|
||||||
if block == "help" {
|
|
||||||
// 输出模板
|
|
||||||
ctx.SendChain(
|
ctx.SendChain(
|
||||||
message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"),
|
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||||
message.Text(
|
message.Text("在线运行代码功能已被禁用"),
|
||||||
">runcode ", language, "\n",
|
|
||||||
templates[language],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if output, err := runCode(block, runType); err != nil {
|
// 执行运行
|
||||||
// 运行失败
|
block := ctx.State["regex_matched"].([]string)[2]
|
||||||
|
block = message.UnescapeCQCodeText(block)
|
||||||
|
if block == "help" {
|
||||||
|
// 输出模板
|
||||||
ctx.SendChain(
|
ctx.SendChain(
|
||||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"),
|
||||||
message.Text("ERROR: ", err),
|
message.Text(
|
||||||
|
">runcode ", language, "\n",
|
||||||
|
templates[language],
|
||||||
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// 运行成功
|
if output, err := runCode(block, runType); err != nil {
|
||||||
ctx.SendChain(
|
// 运行失败
|
||||||
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
ctx.SendChain(
|
||||||
message.Text(output),
|
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||||
)
|
message.Text("ERROR: ", err),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// 运行成功
|
||||||
|
ctx.SendChain(
|
||||||
|
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
|
||||||
|
message.Text(output),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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