🎉 job增加注入指令结果

This commit is contained in:
源文雨 2022-03-07 22:49:19 +08:00
parent ea56c7d0d2
commit 54c9857219
5 changed files with 54 additions and 17 deletions

View File

@ -71,6 +71,7 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地
- [x] 取消在"cron"触发的指令
- [x] 查看所有触发指令
- [x] 查看在"cron"触发的指令
- [x] 注入指令结果:任意指令
- **聊天** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/chat"`
- [x] [BOT名字]
- [x] [戳一戳BOT]
@ -120,6 +121,7 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地
- **在线代码运行** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode"`
- [x] > runcode [language] help
- [x] > runcode [language] [code block]
- [x] > runcoderaw [language] [code block]
- **点歌** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/music"`
- [x] 点歌[xxx]
- [x] 网易点歌[xxx]

4
go.mod
View File

@ -5,7 +5,7 @@ go 1.17
require (
github.com/FloatTech/AnimeAPI v1.3.1-0.20220307053346-aa76aec4b635
github.com/FloatTech/sqlite v0.2.1
github.com/FloatTech/zbputils v1.3.1-0.20220307063102-42185420359d
github.com/FloatTech/zbputils v1.3.1-0.20220307143543-1139754cacdf
github.com/antchfx/htmlquery v1.2.4
github.com/corona10/goimagehash v1.0.3
github.com/fogleman/gg v1.3.0
@ -21,7 +21,7 @@ require (
github.com/shirou/gopsutil/v3 v3.22.2
github.com/sirupsen/logrus v1.8.1
github.com/tidwall/gjson v1.14.0
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220304040741-8e53f210618c
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220307142419-a1b34e6da007
golang.org/x/image v0.0.0-20220302094943-723b81ca9867
)

7
go.sum
View File

@ -4,8 +4,8 @@ github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9
github.com/FloatTech/sqlite v0.2.1 h1:9t6Me48XJJCIoPy4nLRvcdhcVKfT0c2lilp7SEKROG8=
github.com/FloatTech/sqlite v0.2.1/go.mod h1:6NfHRzqOo9RWeMJEoAQVuo51Omd5LFNxCNQhMF02/9U=
github.com/FloatTech/zbputils v1.3.1-0.20220307053255-29a0c0203693/go.mod h1:1nzt5KFkggpZaqkW0faY3y0X/qeMKTodqWc8wbVYhoY=
github.com/FloatTech/zbputils v1.3.1-0.20220307063102-42185420359d h1:G5rXr46dJnpVbU2jN5XevX3lhh2TQ+DkSk1n1TLS82o=
github.com/FloatTech/zbputils v1.3.1-0.20220307063102-42185420359d/go.mod h1:nW53pKNJVrbYzSGr89CBuM1vZv/hnQnV8dJSp+NCeAA=
github.com/FloatTech/zbputils v1.3.1-0.20220307143543-1139754cacdf h1:891FSWb/olANthyZpmsqLWc8Xqr9yKxNOlRjZeHF/c8=
github.com/FloatTech/zbputils v1.3.1-0.20220307143543-1139754cacdf/go.mod h1:u+PiX1khNvtAgfRVTVP4hkA2oUnn5q5dTZSk1Cgp0Gw=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=
@ -162,8 +162,9 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220304040741-8e53f210618c h1:0ew7cwYvRZUm1nsn4Cn0HBDSxy0YT5JnudeP53JwwjA=
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220304040741-8e53f210618c/go.mod h1:NwXIp7PgjV+kUALMXJ4v4/3QcsRSOodtjhLekuPXFog=
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220307142419-a1b34e6da007 h1:yHCJCj8u3Y0JDgTlrUqPHxIO6KU0WK9+voECZ2im5lo=
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220307142419-a1b34e6da007/go.mod h1:NwXIp7PgjV+kUALMXJ4v4/3QcsRSOodtjhLekuPXFog=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=

View File

@ -2,8 +2,10 @@
package job
import (
"encoding/json"
"hash/crc64"
"strconv"
"strings"
"sync"
"time"
@ -30,7 +32,7 @@ var (
func init() {
en := control.Register("job", order.AcquirePrio(), &control.Options{
DisableOnDefault: false,
Help: "定时指令触发器\n- 记录在\"cron\"触发的指令\n- 取消在\"cron\"触发的指令\n- 查看所有触发指令\n- 查看在\"cron\"触发的指令",
Help: "定时指令触发器\n- 记录在\"cron\"触发的指令\n- 取消在\"cron\"触发的指令\n- 查看所有触发指令\n- 查看在\"cron\"触发的指令\n- 注入指令结果:任意指令",
PrivateDataFolder: "job",
})
db.DBPath = en.DataFolder() + "job.db"
@ -144,6 +146,34 @@ func init() {
}
ctx.SendChain(message.Text(lst))
})
en.OnPrefix("注入指令结果:", ctxext.UserOrGrpAdmin, islonotnil).SetBlock(true).Handle(func(ctx *zero.Ctx) {
command := ctx.State["args"].(string)
if command != "" {
vevent.NewLoopOf(vevent.NewAPICallerHook(ctx, func(rsp zero.APIResponse, err error) {
if err == nil {
logrus.Debugln("[job] CallerHook returned")
id := message.NewMessageID(rsp.Data.Get("message_id").String())
msg := ctx.GetMessage(id)
ctx.Event.NativeMessage = json.RawMessage("\"" + msg.Elements.String() + "\"")
ctx.Event.RawMessageID = json.RawMessage(msg.MessageId.String())
ctx.Event.RawMessage = msg.Elements.String()
time.Sleep(time.Second * 5) // 防止风控
ctx.Event.Time = time.Now().Unix()
vev, cl := binary.OpenWriterF(func(w *binary.Writer) {
err = json.NewEncoder(w).Encode(ctx.Event)
})
if err != nil {
cl()
ctx.SendChain(message.Text("ERROR:", err))
return
}
logrus.Debugln("[job] inject:", binary.BytesToString(vev))
inject(ctx.Event.SelfID, vev)()
cl()
}
})).Echo([]byte(strings.ReplaceAll(ctx.Event.RawEvent.Raw, "\"注入指令结果:", "\"")))
}
})
}
func islonotnil(ctx *zero.Ctx) bool {

View File

@ -104,9 +104,10 @@ func init() {
"JavaScript || TypeScript || PHP || Shell \n" +
"Kotlin || Rust || Erlang || Ruby || Swift \n" +
"R || VB || Py2 || Perl || Pascal || Scala",
}).ApplySingle(ctxext.DefaultSingle).OnRegex(`^>runcode\s(.+?)\s([\s\S]+)$`).SetBlock(true).Limit(ctxext.LimitByUser).
}).ApplySingle(ctxext.DefaultSingle).OnRegex(`^>runcode(raw)?\s(.+?)\s([\s\S]+)$`).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
language := ctx.State["regex_matched"].([]string)[1]
israw := ctx.State["regex_matched"].([]string)[1] != ""
language := ctx.State["regex_matched"].([]string)[2]
language = strings.ToLower(language)
if runType, exist := table[language]; !exist {
// 不支持语言
@ -116,10 +117,9 @@ func init() {
)
} else {
// 执行运行
block := ctx.State["regex_matched"].([]string)[2]
block = message.UnescapeCQCodeText(block)
if block == "help" {
// 输出模板
block := message.UnescapeCQCodeText(ctx.State["regex_matched"].([]string)[3])
switch block {
case "help":
ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, " ", language, "-template:\n"),
message.Text(
@ -127,7 +127,7 @@ func init() {
templates[language],
),
)
} else {
default:
if output, err := runCode(block, runType); err != nil {
// 运行失败
ctx.SendChain(
@ -136,6 +136,9 @@ func init() {
)
} else {
// 运行成功
if israw {
ctx.SendChain(message.Text(output))
} else {
ctx.SendChain(
message.Text("> ", ctx.Event.Sender.NickName, "\n"),
message.Text(output),
@ -143,6 +146,7 @@ func init() {
}
}
}
}
})
}