🎨 改进代码结构

This commit is contained in:
Yiwen-Chan 2021-06-29 19:22:41 +08:00
parent f9f7fa08fb
commit 5badee55e0
5 changed files with 59 additions and 29 deletions

View File

@ -79,7 +79,7 @@
- 搜图 `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao"` - 搜图 `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao"`
- [x] 以图搜图|搜索图片|以图识图[图片] - [x] 以图搜图|搜索图片|以图识图[图片]
- [x] 搜图[P站图片ID] - [x] 搜图[P站图片ID]
- 简易随机图片(调用url) `暂时失效` - 简易随机图片(调用url) `github.com/FloatTech/ZeroBot-Plugin/plugin_rand_image`
- [x] 随机图片 - [x] 随机图片
- [x] 直接随机无r18检测后果自负 - [x] 直接随机无r18检测后果自负
- [x] 设置随机图片网址[url] - [x] 设置随机图片网址[url]

12
main.go
View File

@ -20,14 +20,16 @@ import (
//_ "github.com/FloatTech/ZeroBot-ACGImage" //简易随机图片 //_ "github.com/FloatTech/ZeroBot-ACGImage" //简易随机图片
// 嘉然相关 // b站相关
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // 查询b站用户信息
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_diana" // 嘉心糖发病 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_diana" // 嘉心糖发病
// 二次元图片 // 二次元图片
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_lolicon" // lolicon 随机图片 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_image_finder" // 关键字搜图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao" // 以图搜图 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_lolicon" // lolicon 随机图片
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime" // 来份涩图 _ "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" zero "github.com/wdvxdr1123/ZeroBot"

View File

@ -1,15 +1,15 @@
package setutime package plugin_image_finder
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"math/rand" "math/rand"
"net/http" "net/http"
"time" "time"
)
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
type AutoGenerated struct { type AutoGenerated struct {
Illusts []struct { Illusts []struct {
@ -57,7 +57,6 @@ type AutoGenerated struct {
SearchSpanLimit int `json:"search_span_limit"` SearchSpanLimit int `json:"search_span_limit"`
} }
func init() { func init() {
zero.OnRegex(`^来张 (.*)$`, zero.AdminPermission). zero.OnRegex(`^来张 (.*)$`, zero.AdminPermission).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
@ -67,19 +66,17 @@ func init() {
rannum := Suiji() rannum := Suiji()
pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:] pom2 := soutujson.Illusts[rannum].ImageUrls.Large[19:]
ctx.SendChain(message.Image(pom1 + pom2)) ctx.SendChain(message.Image(pom1 + pom2))
}) })
} }
// 请求api // 请求api
func soutuapi(keyword string) *AutoGenerated { func soutuapi(keyword string) *AutoGenerated {
url := "https://api.pixivel.moe/pixiv?type=search&page=0&mode=partial_match_for_tags&word=" + keyword url := "https://api.pixivel.moe/pixiv?type=search&page=0&mode=partial_match_for_tags&word=" + keyword
method := "GET" method := "GET"
client := &http.Client { client := &http.Client{}
}
req, err := http.NewRequest(method, url, nil) req, err := http.NewRequest(method, url, nil)
if err != nil { if err != nil {

View File

@ -1,4 +1,4 @@
package setutime package plugin_rand_image
import ( import (
"fmt" "fmt"

View File

@ -1,7 +1,9 @@
package setutime package plugin_rand_image
import ( import (
"fmt"
"strings" "strings"
"time"
zero "github.com/wdvxdr1123/ZeroBot" zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/message"
@ -39,7 +41,7 @@ func init() { // 插件主体
ctx.Send("请稍后再试哦") ctx.Send("请稍后再试哦")
} else { } else {
BLOCK_REQUEST = true 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 last_group_id := ctx.Event.GroupID
MsgofGrp[last_group_id] = last_message_id MsgofGrp[last_group_id] = last_message_id
BLOCK_REQUEST = false BLOCK_REQUEST = false
@ -57,18 +59,47 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
Vote(ctx, 6) Vote(ctx, 6)
}) })
/* // 上传一张图进行评价
// 上传一张图进行评价 zero.OnFullMatch("评价图片").SetBlock(true).SetPriority(24).
zero.OnFullMatch("评价图片", MustHasPicture()).SetBlock(true).SetPriority(24). Handle(func(ctx *zero.Ctx) {
Handle(func(ctx *zero.Ctx) { // 匹配图片
if ctx.Event.GroupID > 0 { rule := func() zero.Rule {
ctx.Send("少女祈祷中......") return func(ctx *zero.Ctx) bool {
for _, pic := range ctx.State["image_url"].([]string) { var urls = []string{}
fmt.Println(pic) for _, elem := range ctx.Event.Message {
Classify(ctx, pic, true) 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 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
})
} }