diff --git a/README.md b/README.md index cdfbc13c..805efef3 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,8 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ... - **书评** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_book_review"` - [x] 书评[关键字] - [x] 随机书评 +- **coser** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" ` + - [x] coser - **TODO...** ## 使用方法 diff --git a/control/rule.go b/control/rule.go index 64e65e0d..49fb0658 100644 --- a/control/rule.go +++ b/control/rule.go @@ -310,13 +310,13 @@ func init() { ctx.SendChain(message.Text(msg)) }) - zero.OnCommandGroup([]string{"服务详情", "service_detail"}, userOrGrpAdmin). + zero.OnCommandGroup([]string{"服务详情", "service_detail"}, userOrGrpAdmin, zero.OnlyGroup). Handle(func(ctx *zero.Ctx) { var m message.Message m = append(m, message.CustomNode( - ctx.Event.Sender.NickName, - ctx.Event.UserID, + zero.BotConfig.NickName[0], + ctx.Event.SelfID, "---服务详情---", )) i := 0 @@ -333,17 +333,19 @@ func init() { msg += "\n" + help m = append(m, message.CustomNode( - ctx.Event.Sender.NickName, - ctx.Event.UserID, + zero.BotConfig.NickName[0], + ctx.Event.SelfID, msg, )) return true }) - ctx.SendGroupForwardMessage( + if id := ctx.SendGroupForwardMessage( ctx.Event.GroupID, m, - ) + ).Get("message_id").Int(); id == 0 { + ctx.SendChain(message.Text("ERROR: 可能被风控了")) + } }) } } diff --git a/go.mod b/go.mod index aa58b43a..b05ffa2b 100644 --- a/go.mod +++ b/go.mod @@ -24,5 +24,6 @@ require ( github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 github.com/tidwall/gjson v1.12.1 github.com/wdvxdr1123/ZeroBot v1.4.1 + github.com/yusufpapurcu/wmi v1.2.2 // indirect golang.org/x/image v0.0.0-20211028202545-6944b10bf410 ) diff --git a/main.go b/main.go index c41450c5..b2daa870 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin_ai_false" // 服务器监控 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_book_review" // 哀伤雪刃吧推书记录 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_choose" // 选择困难症帮手 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" // 三次元小姐姐 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_fortune" // 运势 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager diff --git a/plugin_coser/coser.go b/plugin_coser/coser.go new file mode 100644 index 00000000..65ebefea --- /dev/null +++ b/plugin_coser/coser.go @@ -0,0 +1,66 @@ +package plugin_coser + +import ( + "github.com/tidwall/gjson" + "time" + + log "github.com/sirupsen/logrus" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/extension/rate" + "github.com/wdvxdr1123/ZeroBot/message" + "github.com/wdvxdr1123/ZeroBot/utils/helper" + + "github.com/FloatTech/ZeroBot-Plugin/control" + "github.com/FloatTech/ZeroBot-Plugin/utils/web" +) + +var ( + engine = control.Register("coser", &control.Options{ + DisableOnDefault: false, + Help: "三次元小姐姐\n- coser\n", + }) + prio = 20 + ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36" + coserURL = "http://ovooa.com/API/cosplay/api.php" + limit = rate.NewManager(time.Minute, 5) +) + +func init() { + engine.OnFullMatch("coser", zero.OnlyGroup).SetBlock(true).SetPriority(prio). + Handle(func(ctx *zero.Ctx) { + if !limit.Load(ctx.Event.GroupID).Acquire() { + ctx.SendChain(message.Text("请稍后重试0x0...")) + return + } + ctx.SendChain(message.Text("少女祈祷中......")) + data, err := web.ReqWith(coserURL, "GET", "", ua) + if err != nil { + log.Println("err为:", err) + } + var m message.Message + text := gjson.Get(helper.BytesToString(data), "data.Title").String() + m = append(m, + message.CustomNode( + zero.BotConfig.NickName[0], + ctx.Event.SelfID, + text, + )) + gjson.Get(helper.BytesToString(data), "data.data").ForEach(func(_, value gjson.Result) bool { + imgcq := `[CQ:image,file=` + value.String() + `]` + m = append(m, + message.CustomNode( + zero.BotConfig.NickName[0], + ctx.Event.SelfID, + imgcq), + ) + return true + }) + + if id := ctx.SendGroupForwardMessage( + ctx.Event.GroupID, + m).Get("message_id").Int(); id == 0 { + ctx.SendChain(message.Text("ERROR: 可能被风控了")) + } + + }) +} diff --git a/plugin_hs/run.go b/plugin_hs/run.go index b6a9ba8f..e1f36348 100644 --- a/plugin_hs/run.go +++ b/plugin_hs/run.go @@ -85,16 +85,19 @@ func init() { sk = append( sk, message.CustomNode( - ctx.Event.Sender.NickName, - ctx.Event.UserID, + zero.BotConfig.NickName[0], + ctx.Event.SelfID, imgcq, // 图片 ), ) } - ctx.SendGroupForwardMessage( + if id := ctx.SendGroupForwardMessage( ctx.Event.GroupID, sk, - ) + ).Get("message_id").Int(); id == 0 { + ctx.SendChain(message.Text("ERROR: 可能被风控了")) + } + }) // 卡组 engine.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`). diff --git a/plugin_vtb_quotation/vtb_quotation.go b/plugin_vtb_quotation/vtb_quotation.go index 2f5706d7..fab4d3b0 100644 --- a/plugin_vtb_quotation/vtb_quotation.go +++ b/plugin_vtb_quotation/vtb_quotation.go @@ -42,7 +42,9 @@ func init() { defer db.Close() defer cancel() firstStepMessage := db.GetAllFirstCategoryMessage() - ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(firstStepMessage)) + if id := ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(firstStepMessage)); id == 0 { + ctx.SendChain(message.Text("ERROR: 可能被风控了")) + } // 步骤0,1,2,依次选择3个类别 step := 0 // 错误次数