add rough guild support

This commit is contained in:
fumiama 2022-01-17 23:04:32 +08:00
parent 461dc925af
commit 8256658ac2
14 changed files with 33 additions and 35 deletions

6
go.mod
View File

@ -3,8 +3,8 @@ module github.com/FloatTech/ZeroBot-Plugin
go 1.17 go 1.17
require ( require (
github.com/FloatTech/AnimeAPI v1.2.4-beta3 github.com/FloatTech/AnimeAPI v1.2.4-beta4
github.com/FloatTech/zbputils v1.2.4-beta3 github.com/FloatTech/zbputils v1.2.4-beta4
github.com/antchfx/htmlquery v1.2.4 github.com/antchfx/htmlquery v1.2.4
github.com/chromedp/chromedp v0.7.6 github.com/chromedp/chromedp v0.7.6
github.com/corona10/goimagehash v1.0.3 github.com/corona10/goimagehash v1.0.3
@ -20,7 +20,7 @@ require (
github.com/shirou/gopsutil/v3 v3.21.12 github.com/shirou/gopsutil/v3 v3.21.12
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.8.1
github.com/tidwall/gjson v1.12.1 github.com/tidwall/gjson v1.12.1
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220116120140-cd6069eba722 github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220117142919-4ad1916ac4c8
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 golang.org/x/image v0.0.0-20211028202545-6944b10bf410
) )

12
go.sum
View File

@ -1,8 +1,8 @@
github.com/FloatTech/AnimeAPI v1.2.4-beta3 h1:635e2vSmurBJXfcnQM1Vo0s6gj3juVHPzXXx2B5ud8M= github.com/FloatTech/AnimeAPI v1.2.4-beta4 h1:eOfgF94DQCWExvdyDj9kWQHH7b1zI7dHnOlldwHYfbE=
github.com/FloatTech/AnimeAPI v1.2.4-beta3/go.mod h1:iPDCjwhWVxRWeRcBZTtxnlEr3oYpuSOjPDAzy8D330k= github.com/FloatTech/AnimeAPI v1.2.4-beta4/go.mod h1:gisq6pI4YN4BL6MLafRYIvb1h14TJmQOH/Jff75iWf0=
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ= github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
github.com/FloatTech/zbputils v1.2.4-beta3 h1:qMfBEoB1r4HaSw4vKRrugMMxctEa7a0h10k3Zwnm49k= github.com/FloatTech/zbputils v1.2.4-beta4 h1:ghZ15qXSy8avn4ZSDsiA+pzOyUrxUjJRfEt9NibO4xE=
github.com/FloatTech/zbputils v1.2.4-beta3/go.mod h1:kF36a1wKBZLvWaHFetpIJixMN8Qtzc3F6s7KBIK7DLA= github.com/FloatTech/zbputils v1.2.4-beta4/go.mod h1:4UzrG5qle4Dd7vVAljgEun0TSfzZDI7L+XTqGPLPu2s=
github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb h1:Rkj28fqIwGx/EgBzRYtpmJRfH6wqVn7cNdc7aJ0QE4M= github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb h1:Rkj28fqIwGx/EgBzRYtpmJRfH6wqVn7cNdc7aJ0QE4M=
github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so= github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
@ -163,8 +163,8 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/wdvxdr1123/ZeroBot v1.3.2/go.mod h1:i2DIqQjtjE+3gvVi9r9sc+QpNaUuyTXx/HNXXayIpwI= github.com/wdvxdr1123/ZeroBot v1.3.2/go.mod h1:i2DIqQjtjE+3gvVi9r9sc+QpNaUuyTXx/HNXXayIpwI=
github.com/wdvxdr1123/ZeroBot v1.4.1/go.mod h1:7t9m4vDZPwWAmzKlhP6IvUoisOIiqNdm/3AJgiY3+ew= github.com/wdvxdr1123/ZeroBot v1.4.1/go.mod h1:7t9m4vDZPwWAmzKlhP6IvUoisOIiqNdm/3AJgiY3+ew=
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220116120140-cd6069eba722 h1:0KDWodIHPh11BgkyfSxWF7zlaejusCFH8OOZO5dVsJg= github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220117142919-4ad1916ac4c8 h1:AwWe53a7VNoHahybOxXoAeZXTriUWoM2RZyv3EtO6P0=
github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220116120140-cd6069eba722/go.mod h1:7t9m4vDZPwWAmzKlhP6IvUoisOIiqNdm/3AJgiY3+ew= github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220117142919-4ad1916ac4c8/go.mod h1:7t9m4vDZPwWAmzKlhP6IvUoisOIiqNdm/3AJgiY3+ew=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=

View File

@ -27,7 +27,7 @@ const (
var ( var (
// r18有一定保护一般不会发出图片 // r18有一定保护一般不会发出图片
randapi = "&loli=true&r18=true" randapi = "&loli=true&r18=true"
msgof = make(map[int64]int64) msgof = make(map[int64]message.MessageID)
block = false block = false
limit = rate.NewManager(time.Minute, 5) limit = rate.NewManager(time.Minute, 5)
) )
@ -53,7 +53,7 @@ func init() { // 插件主体
} }
}) })
// 有保护的随机图片 // 有保护的随机图片
engine.OnFullMatch("随机图片", zero.OnlyGroup).SetBlock(true). engine.OnFullMatch("随机图片", zero.OnlyPublic).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
if limit.Load(ctx.Event.UserID).Acquire() { if limit.Load(ctx.Event.UserID).Acquire() {
class, dhash, comment, _ := classify.Classify(randapi, true) class, dhash, comment, _ := classify.Classify(randapi, true)
@ -63,7 +63,7 @@ func init() { // 插件主体
ctx.SendChain(message.Text("你太快啦!")) ctx.SendChain(message.Text("你太快啦!"))
}) })
// 直接随机图片无r18保护后果自负。如果出r18图可尽快通过发送"太涩了"撤回 // 直接随机图片无r18保护后果自负。如果出r18图可尽快通过发送"太涩了"撤回
engine.OnFullMatch("直接随机", zero.OnlyGroup, zero.AdminPermission).SetBlock(true). engine.OnFullMatch("直接随机", zero.OnlyPublic, zero.AdminPermission).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
if block { if block {
ctx.SendChain(message.Text("请稍后再试哦")) ctx.SendChain(message.Text("请稍后再试哦"))
@ -89,7 +89,7 @@ func init() { // 插件主体
} }
}) })
// 上传一张图进行评价 // 上传一张图进行评价
engine.OnKeywordGroup([]string{"评价图片"}, zero.OnlyGroup, picture.CmdMatch, picture.MustGiven).SetBlock(true). engine.OnKeywordGroup([]string{"评价图片"}, zero.OnlyPublic, picture.CmdMatch, picture.MustGiven).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text("少女祈祷中...")) ctx.SendChain(message.Text("少女祈祷中..."))
for _, url := range ctx.State["image_url"].([]string) { for _, url := range ctx.State["image_url"].([]string) {
@ -111,7 +111,7 @@ func init() { // 插件主体
}) })
} }
func setLastMsg(id int64, msg int64) { func setLastMsg(id int64, msg message.MessageID) {
msgof[id] = msg msgof[id] = msg
} }

View File

@ -38,7 +38,7 @@ func init() { // 插件主体
reply := aireply.Talk(ctx.ExtractPlainText()) reply := aireply.Talk(ctx.ExtractPlainText())
// 回复 // 回复
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
if ctx.Event.MessageType == "group" { if zero.OnlyPublic(ctx) {
reply = append(reply, message.Reply(ctx.Event.MessageID)) reply = append(reply, message.Reply(ctx.Event.MessageID))
ctx.Send(reply) ctx.Send(reply)
return return

View File

@ -207,7 +207,7 @@ func init() {
if err != nil { if err != nil {
log.Errorln("[bilibilipush]:", err) log.Errorln("[bilibilipush]:", err)
} }
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id == 0 { if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
}) })

View File

@ -27,7 +27,7 @@ func init() {
if err != nil { if err != nil {
log.Println("err:", err) log.Println("err:", err)
} }
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id == 0 { if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
}) })
@ -39,7 +39,7 @@ func init() {
if err != nil { if err != nil {
log.Println("err:", err) log.Println("err:", err)
} }
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id == 0 { if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
}) })

View File

@ -32,7 +32,7 @@ func init() { // 插件主体
"- 鉴赏图片[图片]", "- 鉴赏图片[图片]",
}) })
// 上传一张图进行评价 // 上传一张图进行评价
engine.OnKeywordGroup([]string{"鉴赏图片"}, zero.OnlyGroup, picture.CmdMatch, picture.MustGiven).SetBlock(true). engine.OnKeywordGroup([]string{"鉴赏图片"}, zero.OnlyPublic, picture.CmdMatch, picture.MustGiven).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text("少女祈祷中...")) ctx.SendChain(message.Text("少女祈祷中..."))
for _, url := range ctx.State["image_url"].([]string) { for _, url := range ctx.State["image_url"].([]string) {

View File

@ -5,7 +5,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"math" "math"
"strconv"
"time" "time"
"github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/message"
@ -33,8 +32,7 @@ func init() {
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
msg := ctx.Event.Message msg := ctx.Event.Message
if msg[0].Type == "reply" { if msg[0].Type == "reply" {
id, _ := strconv.Atoi(msg[0].Data["id"]) msg := ctx.GetMessage(message.NewMessageID(msg[0].Data["id"])).Elements[0].Data["text"]
msg := ctx.GetMessage(int64(id)).Elements[0].Data["text"]
zhiwangjson := zhiwangapi(msg) zhiwangjson := zhiwangapi(msg)
if zhiwangjson == nil || zhiwangjson.Code != 0 { if zhiwangjson == nil || zhiwangjson.Code != 0 {

View File

@ -92,7 +92,7 @@ func init() {
if err != nil { if err != nil {
log.Println("err:", err) log.Println("err:", err)
} }
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id == 0 { if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
} else { } else {
@ -124,7 +124,7 @@ func init() {
if err != nil { if err != nil {
log.Println("err:", err) log.Println("err:", err)
} }
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id == 0 { if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
} }

View File

@ -46,7 +46,7 @@ func init() { // 插件主体
if err != nil { if err != nil {
log.Errorln("[omikuji]:", err) log.Errorln("[omikuji]:", err)
} }
if id := ctx.SendChain(message.At(ctx.Event.UserID), message.Image("base64://"+helper.BytesToString(kujiBytes))); id == 0 { if id := ctx.SendChain(message.At(ctx.Event.UserID), message.Image("base64://"+helper.BytesToString(kujiBytes))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
}) })

View File

@ -41,7 +41,7 @@ var (
) )
func init() { func init() {
engine.OnFullMatch("签到").SetBlock(true). engine.OnFullMatch("签到", zero.OnlyGroup).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID uid := ctx.Event.UserID
now := time.Now() now := time.Now()

View File

@ -118,7 +118,7 @@ func init() { // 插件主体
} }
} }
// 从缓冲池里抽一张 // 从缓冲池里抽一张
if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); id == 0 { if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
}) })
@ -142,7 +142,7 @@ func init() { // 插件主体
return return
} }
// 发送到发送者 // 发送到发送者
if id := ctx.SendChain(message.Image(file(illust))); id == 0 { if id := ctx.SendChain(message.Image(file(illust))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控,发送失败")) ctx.SendChain(message.Text("ERROR: 可能被风控,发送失败"))
return return
} }

View File

@ -58,7 +58,7 @@ func handle(ctx *zero.Ctx) {
if err != nil { if err != nil {
log.Errorln("[shindan]:", err) log.Errorln("[shindan]:", err)
} }
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id == 0 { if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
default: default:

View File

@ -52,7 +52,7 @@ func init() {
if err != nil { if err != nil {
log.Errorln("[vtb]:", err) log.Errorln("[vtb]:", err)
} }
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id == 0 { if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
// 步骤012依次选择3个类别 // 步骤012依次选择3个类别
@ -84,7 +84,7 @@ func init() {
if err != nil { if err != nil {
log.Errorln("[vtb]:", err) log.Errorln("[vtb]:", err)
} }
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id == 0 { if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
errorCount++ errorCount++
@ -93,7 +93,7 @@ func init() {
if err != nil { if err != nil {
log.Errorln("[vtb]:", err) log.Errorln("[vtb]:", err)
} }
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(secondStepMessageBytes))); id == 0 { if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(secondStepMessageBytes))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
step++ step++
@ -115,7 +115,7 @@ func init() {
if err != nil { if err != nil {
log.Errorln("[vtb]:", err) log.Errorln("[vtb]:", err)
} }
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(secondStepMessageBytes))); id == 0 { if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(secondStepMessageBytes))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
errorCount++ errorCount++
@ -124,7 +124,7 @@ func init() {
if err != nil { if err != nil {
log.Errorln("[vtb]:", err) log.Errorln("[vtb]:", err)
} }
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(thirdStepMessageBytes))); id == 0 { if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(thirdStepMessageBytes))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
step++ step++
@ -147,7 +147,7 @@ func init() {
if err != nil { if err != nil {
log.Errorln("[vtb]:", err) log.Errorln("[vtb]:", err)
} }
if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id == 0 { if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("base64://"+helper.BytesToString(firstStepImageBytes))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
errorCount++ errorCount++