diff --git a/README.md b/README.md index 2d74b037..36cdc2ea 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ - 搜图 `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao"` - [x] 以图搜图|搜索图片|以图识图[图片] - [x] 搜图[P站图片ID] -- 简易随机图片(调用url) `暂时失效` +- 简易随机图片(调用url) `github.com/FloatTech/ZeroBot-Plugin/plugin_rand_image` - [x] 随机图片 - [x] 直接随机(无r18检测,后果自负) - [x] 设置随机图片网址[url] diff --git a/main.go b/main.go index 25a7da22..90fa3d88 100644 --- a/main.go +++ b/main.go @@ -20,14 +20,16 @@ import ( //_ "github.com/FloatTech/ZeroBot-ACGImage" //简易随机图片 - // 嘉然相关 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // + // b站相关 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // 查询b站用户信息 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_diana" // 嘉心糖发病 // 二次元图片 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_lolicon" // lolicon 随机图片 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao" // 以图搜图 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime" // 来份涩图 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_image_finder" // 关键字搜图 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_lolicon" // lolicon 随机图片 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_rand_image" // 随机图片 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao" // 以图搜图 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime" // 来份涩图 // 以下为内置依赖,勿动 zero "github.com/wdvxdr1123/ZeroBot" diff --git a/setutime/keyword.go b/plugin_image_finder/keyword.go similarity index 97% rename from setutime/keyword.go rename to plugin_image_finder/keyword.go index 1744f41d..ae7f93b5 100644 --- a/setutime/keyword.go +++ b/plugin_image_finder/keyword.go @@ -1,15 +1,15 @@ -package setutime +package plugin_image_finder import ( "encoding/json" "fmt" - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" "math/rand" "net/http" "time" -) + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" +) type AutoGenerated struct { Illusts []struct { @@ -57,7 +57,6 @@ type AutoGenerated struct { SearchSpanLimit int `json:"search_span_limit"` } - func init() { zero.OnRegex(`^来张 (.*)$`, zero.AdminPermission). Handle(func(ctx *zero.Ctx) { @@ -67,19 +66,17 @@ func init() { rannum := Suiji() pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:] ctx.SendChain(message.Image(pom1 + pom2)) - }) + }) } - // 请求api func soutuapi(keyword string) *AutoGenerated { url := "https://api.pixivel.moe/pixiv?type=search&page=0&mode=partial_match_for_tags&word=" + keyword method := "GET" - client := &http.Client { - } + client := &http.Client{} req, err := http.NewRequest(method, url, nil) if err != nil { diff --git a/setutime/classify.go b/plugin_rand_image/classify.go similarity index 99% rename from setutime/classify.go rename to plugin_rand_image/classify.go index 2a8e269c..9351a169 100644 --- a/setutime/classify.go +++ b/plugin_rand_image/classify.go @@ -1,4 +1,4 @@ -package setutime +package plugin_rand_image import ( "fmt" diff --git a/setutime/rand_image.go b/plugin_rand_image/rand_image.go similarity index 57% rename from setutime/rand_image.go rename to plugin_rand_image/rand_image.go index a46d14bc..ce38e597 100644 --- a/setutime/rand_image.go +++ b/plugin_rand_image/rand_image.go @@ -1,7 +1,9 @@ -package setutime +package plugin_rand_image import ( + "fmt" "strings" + "time" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" @@ -39,7 +41,7 @@ func init() { // 插件主体 ctx.Send("请稍后再试哦") } else { BLOCK_REQUEST = true - last_message_id := ctx.SendChain(message.Image(RANDOM_API_URL).Add("no_cache", "0")) + last_message_id := ctx.SendChain(message.Image(RANDOM_API_URL).Add("cache", "0")) last_group_id := ctx.Event.GroupID MsgofGrp[last_group_id] = last_message_id BLOCK_REQUEST = false @@ -57,18 +59,47 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { Vote(ctx, 6) }) - /* - // 上传一张图进行评价 - zero.OnFullMatch("评价图片", MustHasPicture()).SetBlock(true).SetPriority(24). - Handle(func(ctx *zero.Ctx) { - if ctx.Event.GroupID > 0 { - ctx.Send("少女祈祷中......") - for _, pic := range ctx.State["image_url"].([]string) { - fmt.Println(pic) - Classify(ctx, pic, true) + // 上传一张图进行评价 + zero.OnFullMatch("评价图片").SetBlock(true).SetPriority(24). + Handle(func(ctx *zero.Ctx) { + // 匹配图片 + rule := func() zero.Rule { + return func(ctx *zero.Ctx) bool { + var urls = []string{} + for _, elem := range ctx.Event.Message { + if elem.Type == "image" { + urls = append(urls, elem.Data["url"]) + } } + if len(urls) > 0 { + ctx.State["image_url"] = urls + return true + } + return false } + } + // 索取图片 + ctx.SendChain(message.Text("请发送一张图片")) + next := zero.NewFutureEvent("message", 999, false, zero.CheckUser(ctx.Event.UserID), rule()) + recv, cancel := next.Repeat() + select { + case <-time.After(time.Second * 120): return - }) - */ + case e := <-recv: + cancel() + newCtx := &zero.Ctx{Event: e, State: zero.State{}} + if rule()(newCtx) { + ctx.State["image_url"] = newCtx.State["image_url"] + } + } + if ctx.Event.GroupID > 0 { + ctx.Send("少女祈祷中......") + for _, pic := range ctx.State["image_url"].([]string) { + fmt.Println(pic) + Classify(ctx, pic, true) + } + } + return + }) + }