应用插件控制到大部分插件

This commit is contained in:
fumiama 2021-09-09 11:13:23 +08:00
parent cb3cfa054b
commit 91396c8885
14 changed files with 155 additions and 146 deletions

View File

@ -66,8 +66,7 @@
- [x] >github [xxx]
- [x] >github -p [xxx]
- **在线代码运行** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_runcode"`
- [x] > runcode help
- [x] > runcode [on/off]
- [x] > runcode [language] help
- [x] > runcode [language] [code block]
- **点歌** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_music"`
- [x] 点歌[xxx]
@ -118,7 +117,9 @@
- [ ] 简易语音
- [ ] 爬图合成 [@xxx]
- **minecraft** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft"`
- [x] 具体指令看代码
- [x] /mcstart xxx
- [x] /mcstop xxx
- [x] /mclist servername
- 注:此功能实现依赖[MCSManager](https://github.com/Suwings/MCSManager)项目对服务器的管理apimc服务器如果没有在该管理平台部署此功能无效
- **炉石** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs"`
- [x] 搜卡[xxxx]
@ -126,8 +127,6 @@
- 注更多搜卡指令参数https://hs.fbigame.com/misc/searchhelp
- **青云客** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_qingyunke"`
- [x] @Bot 任意文本(任意一句话回复)
- [x] 关闭自动回复
- [x] 启动自动回复
- **关键字搜图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_image_finder"`
- [x] 来张 [xxx]
- **TODO...**

View File

@ -20,12 +20,11 @@ func init() { // 插件主体
// TODO: 1.17 特性暂不增加
// rand.Seed(time.Now().UnixMicro())
rand.Seed(time.Now().UnixNano())
engine := control.Register("aiwife", &control.Options{
control.Register("aiwife", &control.Options{
DisableOnDefault: false,
Help: "AIWife\n" +
"- waifu|随机waifu",
})
engine.OnFullMatchGroup([]string{"waifu", "随机waifu"}).SetPriority(10).
}).OnFullMatchGroup([]string{"waifu", "随机waifu"}).SetPriority(10).
Handle(func(ctx *zero.Ctx) {
miku := rand.Intn(100000) + 1
ctx.SendChain(message.At(ctx.Event.UserID), message.Image(fmt.Sprintf(bed, miku)))

View File

@ -18,13 +18,12 @@ import (
)
func init() { // 插件主体
engine := control.Register("github", &control.Options{
control.Register("github", &control.Options{
DisableOnDefault: false,
Help: "GitHub仓库搜索\n" +
"- >github [xxx]\n" +
"- >github -p [xxx]",
})
engine.OnRegex(`^>github\s(-.{1,10}? )?(.*)$`).SetBlock(true).FirstPriority().
}).OnRegex(`^>github\s(-.{1,10}? )?(.*)$`).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
// 发送请求
header := http.Header{

View File

@ -61,12 +61,11 @@ type resultjson struct {
}
func init() {
engine := control.Register("imgfinder", &control.Options{
control.Register("imgfinder", &control.Options{
DisableOnDefault: false,
Help: "关键字搜图\n" +
"- 来张 [xxx]",
})
engine.OnRegex(`^来张 (.*)$`, zero.AdminPermission).
}).OnRegex(`^来张 (.*)$`, zero.AdminPermission).
Handle(func(ctx *zero.Ctx) {
keyword := ctx.State["regex_matched"].([]string)[1]
soutujson := soutuapi(keyword)

View File

@ -6,6 +6,7 @@ import (
"net/http"
"time"
"github.com/FloatTech/ZeroBot-Plugin/control"
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
@ -21,7 +22,11 @@ var (
)
func init() {
zero.OnFullMatch("来份萝莉").
control.Register("lolicon", &control.Options{
DisableOnDefault: false,
Help: "lolicon\n" +
"- 来份萝莉",
}).OnFullMatch("来份萝莉").
Handle(func(ctx *zero.Ctx) {
go func() {
for i := 0; i < min(cap(queue)-len(queue), 2); i++ {

View File

@ -7,6 +7,7 @@ import (
"strings"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension"
"github.com/wdvxdr1123/ZeroBot/message"
)
@ -36,22 +37,21 @@ type resultjson struct {
} `json:"players"`
}
var (
servers = make(map[string]string)
)
func init() {
zero.OnRegex(`^/list (.*)$`).
// 这里填对应mc服务器的登录地址
servers["ftbi"] = "115.28.186.22:25710"
servers["ges"] = "115.28.186.22:25701"
engine.OnCommand("mclist").
Handle(func(ctx *zero.Ctx) {
model := extension.CommandModel{}
_ = ctx.Parse(&model)
// 支持多个服务器
switch ctx.State["regex_matched"].([]string)[1] {
case "ftbi": // 这里对应触发指令里的服务器名称
ftbijson := infoapi("115.28.186.22:25710") // 这里填对应mc服务器的登录地址
var str = ftbijson.Players.List
cs := strings.Join(str, "\n")
ctx.SendChain(message.Text(
"服务器名字: ", ftbijson.Motd.Raw[0], "\n",
"在线人数: ", ftbijson.Players.Online, "/", ftbijson.Players.Max, "\n",
"以下为玩家名字: ", "\n", cs,
))
case "ges": // 这里对应触发指令里的服务器名称
gesjson := infoapi("115.28.186.22:25701") // 这里填对应mc服务器的登录地址
gesjson := infoapi(servers[model.Args])
var str = gesjson.Players.List
cs := strings.Join(str, "\n")
ctx.SendChain(message.Text(
@ -59,7 +59,6 @@ func init() {
"在线人数: ", gesjson.Players.Online, "/", gesjson.Players.Max, "\n",
"以下为玩家名字: ", "\n", cs,
))
}
})
}

View File

@ -6,7 +6,9 @@ import (
"io/ioutil"
"net/http"
"github.com/FloatTech/ZeroBot-Plugin/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension"
"github.com/wdvxdr1123/ZeroBot/message"
)
@ -14,29 +16,40 @@ import (
// 项目地址: https://github.com/Suwings/MCSManager
// 项目的api文档: https://github.com/Suwings/MCSManager/wiki/API-Documentation
func init() {
zero.OnRegex(`^/start (.*)$`).
Handle(func(ctx *zero.Ctx) {
name := ctx.State["regex_matched"].([]string)[1]
ctx.SendChain(message.Text("开启服务器: ", name, "....."))
result := start(name)
ctx.Send(result)
})
}
const api = "http://your.addr:23333/api/start_server/%s/?apikey=apikey"
var engine *zero.Engine
func init() {
zero.OnRegex(`^/stop (.*)$`).
engine = control.Register("minecraft", &control.Options{
DisableOnDefault: false,
Help: "minecraft\n" +
"- /mcstart xxx\n" +
"- /mcstop xxx\n" +
"- /mclist servername\n" +
"- https://github.com/Suwings/MCSManager",
})
engine.OnCommand("mcstart").
Handle(func(ctx *zero.Ctx) {
name := ctx.State["regex_matched"].([]string)[1]
ctx.SendChain(message.Text("关闭服务器: ", name, "....."))
result := stop(name)
model := extension.CommandModel{}
_ = ctx.Parse(&model)
ctx.SendChain(message.Text("开启服务器: ", model.Args, "....."))
result := start(model.Args)
ctx.Send(result)
})
engine.OnCommand("mcstop").
Handle(func(ctx *zero.Ctx) {
model := extension.CommandModel{}
_ = ctx.Parse(&model)
ctx.SendChain(message.Text("开启服务器: ", model.Args, "....."))
result := stop(model.Args)
ctx.Send(result)
})
}
// 开启服务器的api请求
func start(name string) string {
url := fmt.Sprintf("http://your.addr:23333/api/start_server/%s/?apikey=apikey", name)
url := fmt.Sprintf(api, name)
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
@ -57,7 +70,7 @@ func start(name string) string {
// 关闭服务器的api请求
func stop(name string) string {
url := fmt.Sprintf("http://your.addr:23333/api/stop_server/%s/?apikey=apikey", name)
url := fmt.Sprintf(api, name)
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {

View File

@ -11,6 +11,7 @@ import (
"strings"
"time"
"github.com/FloatTech/ZeroBot-Plugin/control"
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
@ -20,7 +21,14 @@ import (
var limit = rate.NewManager(time.Minute*3, 5)
func init() {
zero.OnRegex("^(.{0,2})点歌(.{1,25})$").SetBlock(true).FirstPriority().
control.Register("music", &control.Options{
DisableOnDefault: false,
Help: "点歌\n" +
"- 点歌[xxx]\n" +
"- 网易点歌[xxx]\n" +
"- 酷我点歌[xxx]\n" +
"- 酷狗点歌[xxx]",
}).OnRegex("^(.{0,2})点歌(.{1,25})$").SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.UserID).Acquire() {
ctx.Send("请稍后重试0x0...")

View File

@ -6,6 +6,7 @@ import (
"math/rand"
"time"
"github.com/FloatTech/ZeroBot-Plugin/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
@ -18,7 +19,11 @@ func init() { // 插件主体
// TODO: 1.17 特性暂不增加
// rand.Seed(time.Now().UnixMicro())
rand.Seed(time.Now().UnixNano())
zero.OnFullMatchGroup([]string{"求签", "运势", "占卜"}).SetPriority(10).
control.Register("omikuji", &control.Options{
DisableOnDefault: false,
Help: "浅草寺求签\n" +
"- 求签|运势|占卜",
}).OnFullMatchGroup([]string{"求签", "运势", "占卜"}).SetPriority(10).
Handle(func(ctx *zero.Ctx) {
miku := rand.Intn(100) + 1
ctx.SendChain(

View File

@ -14,6 +14,7 @@ import (
"strings"
"time"
"github.com/FloatTech/ZeroBot-Plugin/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
@ -22,23 +23,17 @@ import (
var (
prio = 3
bucket = rate.NewManager(time.Minute, 20) // 青云客接口回复
enable = true
engine *zero.Engine
)
func init() { // 插件主体
// 开关
zero.OnFullMatch("开启自动回复", zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
enable = true
ctx.SendChain(message.Text("自动回复开启"))
})
zero.OnFullMatch("关闭自动回复", zero.SuperUserPermission).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
enable = false
ctx.SendChain(message.Text("自动回复关闭"))
engine = control.Register("qingyunke", &control.Options{
DisableOnDefault: false,
Help: "青云客\n" +
"- @Bot 任意文本(任意一句话回复)",
})
// 回复
zero.OnRegex("(^.{1,30}$)", zero.OnlyToMe, switchQYK()).SetBlock(false).SetPriority(prio).
engine.OnRegex("(^.{1,30}$)", zero.OnlyToMe).SetBlock(true).SetPriority(prio).
Handle(func(ctx *zero.Ctx) {
if !bucket.Load(ctx.Event.UserID).Acquire() {
// 频繁触发,不回复
@ -152,9 +147,3 @@ func getAgent() string {
len1 := len(agent)
return agent[r.Intn(len1)]
}
func switchQYK() zero.Rule {
return func(ctx *zero.Ctx) bool {
return enable
}
}

View File

@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/FloatTech/ZeroBot-Plugin/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
@ -17,7 +18,6 @@ import (
)
var (
enable = true
limit = rate.NewManager(time.Minute*3, 5)
templates = map[string]string{
"py2": "print 'Hello World!'",
@ -92,40 +92,18 @@ var (
)
func init() {
zero.OnFullMatch(">runcode help").SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text(
"使用说明: ", "\n",
">runcode [language] [code block]", "\n",
"模板查看: ", "\n",
">runcode [language] help", "\n",
"支持语种: ", "\n",
"Go || Python || C/C++ || C# || Java || Lua ", "\n",
"JavaScript || TypeScript || PHP || Shell ", "\n",
"Kotlin || Rust || Erlang || Ruby || Swift ", "\n",
"R || VB || Py2 || Perl || Pascal || Scala ", "\n",
))
})
zero.OnFullMatch(">runcode on", zero.AdminPermission).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
enable = true
ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("在线运行代码功能已启用"),
)
})
zero.OnFullMatch(">runcode off", zero.AdminPermission).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
enable = false
ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("在线运行代码功能已禁用"),
)
})
zero.OnRegex(`^>runcode\s(.+?)\s([\s\S]+)$`).SetBlock(true).SecondPriority().
control.Register("runcode", &control.Options{
DisableOnDefault: false,
Help: "在线代码运行: \n" +
">runcode [language] [code block]\n" +
"模板查看: \n" +
">runcode [language] help\n" +
"支持语种: \n" +
"Go || Python || C/C++ || C# || Java || Lua \n" +
"JavaScript || TypeScript || PHP || Shell \n" +
"Kotlin || Rust || Erlang || Ruby || Swift \n" +
"R || VB || Py2 || Perl || Pascal || Scala",
}).OnRegex(`^>runcode\s(.+?)\s([\s\S]+)$`).SetBlock(true).SecondPriority().
Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.UserID).Acquire() {
ctx.Send("请稍后重试0x0...")
@ -138,13 +116,6 @@ func init() {
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("语言不是受支持的编程语种呢~"),
)
} else {
if !enable {
// 运行代码被禁用
ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text("在线运行代码功能已被禁用"),
)
} else {
// 执行运行
block := ctx.State["regex_matched"].([]string)[2]
@ -175,7 +146,6 @@ func init() {
}
}
}
}
})
}

View File

@ -13,11 +13,18 @@ import (
"github.com/FloatTech/AnimeAPI/picture"
"github.com/FloatTech/AnimeAPI/pixiv"
"github.com/FloatTech/AnimeAPI/saucenao"
"github.com/FloatTech/ZeroBot-Plugin/control"
)
func init() { // 插件主体
engine := control.Register("saucenao", &control.Options{
DisableOnDefault: false,
Help: "搜图\n" +
"- 以图搜图|搜索图片|以图识图[图片]\n" +
"- 搜图[P站图片ID]",
})
// 根据 PID 搜图
zero.OnRegex(`^搜图(\d+)$`).SetBlock(true).FirstPriority().
engine.OnRegex(`^搜图(\d+)$`).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
id, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
ctx.Send("少女祈祷中......")
@ -48,7 +55,7 @@ func init() { // 插件主体
}
})
// 以图搜图
zero.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, picture.CmdMatch, picture.MustGiven).SetBlock(true).FirstPriority().
engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, picture.CmdMatch, picture.MustGiven).SetBlock(true).FirstPriority().
Handle(func(ctx *zero.Ctx) {
// 开始搜索图片
ctx.Send("少女祈祷中......")

View File

@ -12,12 +12,12 @@ import (
"time"
"github.com/FloatTech/AnimeAPI/pixiv"
"github.com/FloatTech/ZeroBot-Plugin/control"
. "github.com/FloatTech/ZeroBot-Plugin/data"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
. "github.com/FloatTech/ZeroBot-Plugin/data"
)
// Pools 图片缓冲池
@ -86,7 +86,15 @@ var (
)
func init() { // 插件主体
zero.OnRegex(`^来份(.*)$`, firstValueInList(pool.List)).SetBlock(true).SetPriority(20).
engine := control.Register("setutime", &control.Options{
DisableOnDefault: false,
Help: "涩图\n" +
"- 来份[涩图/二次元/风景/车万]\n" +
"- 添加[涩图/二次元/风景/车万][P站图片ID]\n" +
"- 删除[涩图/二次元/风景/车万][P站图片ID]\n" +
"- >setu status",
})
engine.OnRegex(`^来份(.*)$`, firstValueInList(pool.List)).SetBlock(true).SetPriority(20).
Handle(func(ctx *zero.Ctx) {
if !limit.Load(ctx.Event.UserID).Acquire() {
ctx.SendChain(message.Text("请稍后重试0x0..."))
@ -130,7 +138,7 @@ func init() { // 插件主体
}
})
zero.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21).
engine.OnRegex(`^添加(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]
@ -161,7 +169,7 @@ func init() { // 插件主体
ctx.Send("添加成功")
})
zero.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
engine.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]
@ -176,7 +184,7 @@ func init() { // 插件主体
})
// 查询数据库涩图数量
zero.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).SetPriority(23).
engine.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).SetPriority(23).
Handle(func(ctx *zero.Ctx) {
state := []string{"[SetuTime]"}
for i := range pool.List {

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/FloatTech/AnimeAPI/shindanmaker"
"github.com/FloatTech/ZeroBot-Plugin/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
@ -17,10 +18,18 @@ var (
)
func init() {
zero.OnPrefix("异世界转生", number(587874)).SetBlock(true).FirstPriority().Handle(handle)
zero.OnPrefix("今天是什么少女", number(162207)).SetBlock(true).FirstPriority().Handle(handle)
zero.OnPrefix("卖萌", number(360578)).SetBlock(true).FirstPriority().Handle(handle)
zero.OnPrefix("抽老婆", number(1075116)).SetBlock(true).FirstPriority().Handle(handle)
engine := control.Register("shindan", &control.Options{
DisableOnDefault: false,
Help: "shindan\n" +
"- 今天是什么少女[@xxx]\n" +
"- 异世界转生[@xxx]\n" +
"- 卖萌[@xxx]\n" +
"- 抽老婆[@xxx]",
})
engine.OnPrefix("异世界转生", number(587874)).SetBlock(true).FirstPriority().Handle(handle)
engine.OnPrefix("今天是什么少女", number(162207)).SetBlock(true).FirstPriority().Handle(handle)
engine.OnPrefix("卖萌", number(360578)).SetBlock(true).FirstPriority().Handle(handle)
engine.OnPrefix("抽老婆", number(1075116)).SetBlock(true).FirstPriority().Handle(handle)
}
// shindanmaker 处理函数