🎨 改进代码结构

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

12
main.go
View File

@ -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"

View File

@ -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 {

View File

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

View File

@ -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
})
}