Skip to content

Commit

Permalink
模块化rand_image
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jul 2, 2021
1 parent 956c741 commit 60dbd0d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 224 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
data/SetuTime/cache
data/SetuTime/search
data/manager
.idea/
.idea/
.DS_Store
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
- 搜图 `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao"`
- [x] 以图搜图|搜索图片|以图识图[图片]
- [x] 搜图[P站图片ID]
- 简易随机图片(调用url) `github.com/FloatTech/ZeroBot-Plugin/plugin_rand_image`
- 随机图片与点评 `github.com/FloatTech/ZeroBot-Plugin/plugin_rand_image`
- [x] 随机图片
- [x] 直接随机(无r18检测,后果自负)
- [x] 设置随机图片网址[url]
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ go 1.16

require (
github.com/FloatTech/AnimeAPI v0.0.0-20210619112022-a8fdd4fefc07
github.com/FloatTech/ZeroBot-ACGImage v1.1.2
github.com/FloatTech/ZeroBot-Plugin-Timer v1.2.2
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/robfig/cron v1.2.0
github.com/shirou/gopsutil v3.21.5+incompatible
github.com/shirou/gopsutil v3.21.6+incompatible
github.com/sirupsen/logrus v1.8.1
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tidwall/gjson v1.8.0
github.com/tidwall/gjson v1.8.1
github.com/tklauser/go-sysconf v0.3.6 // indirect
github.com/wdvxdr1123/ZeroBot v1.2.1
modernc.org/sqlite v1.11.1
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/FloatTech/AnimeAPI v0.0.0-20210619112022-a8fdd4fefc07 h1:7fBPLLoZysaa9PI9ApgzyVMrMLMWBam273YgKwy7Ddg=
github.com/FloatTech/AnimeAPI v0.0.0-20210619112022-a8fdd4fefc07/go.mod h1:GYrQD70HvBzry1XiZ1tHFNOsOqRkR+ao4XGYZqV4I9c=
github.com/FloatTech/ZeroBot-ACGImage v1.1.2 h1:Q+FwOb1vCCYG2B7hPU0uBMzWwB85eVlC0pWRJZ+rBCQ=
github.com/FloatTech/ZeroBot-ACGImage v1.1.2/go.mod h1:CtEYnFTjgzH4v1jaowyyjBmjSKK3p8WPXExfGnVmx1E=
github.com/FloatTech/ZeroBot-Plugin-Timer v1.2.2 h1:I7RSCsJVT6elehdaSiWB4n96y06fQxMsvAG494S5Od0=
github.com/FloatTech/ZeroBot-Plugin-Timer v1.2.2/go.mod h1:femu/wVuqVSN/rg209qksMx8/2OKUF8l1PZCNg4RwVA=
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 h1:5sXbqlSomvdjlRbWyNqkPsJ3Fg+tQZCbgeX1VGljbQY=
Expand Down Expand Up @@ -53,8 +55,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6O
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/shirou/gopsutil v3.21.5+incompatible h1:OloQyEerMi7JUrXiNzy8wQ5XN+baemxSl12QgIzt0jc=
github.com/shirou/gopsutil v3.21.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v3.21.6+incompatible h1:mmZtAlWSd8U2HeRTjswbnDLPxqsEoK01NK+GZ1P+nEM=
github.com/shirou/gopsutil v3.21.6+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
Expand All @@ -67,8 +69,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk=
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ=
github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
github.com/tidwall/gjson v1.8.1 h1:8j5EE9Hrh3l9Od1OIEDAb7IpezNA20UdRngNAj5N0WU=
github.com/tidwall/gjson v1.8.1/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
Expand Down
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"

// 注:以下插件均可通过前面加 // 注释,注释后停用并不加载插件
// 下列插件可与 wdvxdr1123/ZeroBot v1.1.2 以上配合单独使用
Expand All @@ -19,16 +20,14 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_music" // 点歌
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_shindan" // 测定

//_ "github.com/FloatTech/ZeroBot-ACGImage" //简易随机图片

// b站相关
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili" // 查询b站用户信息
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_diana" // 嘉心糖发病

// 二次元图片
_ "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_rand_image" // 随机图片与点评
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_saucenao" // 以图搜图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime" // 来份涩图

Expand Down Expand Up @@ -61,7 +60,7 @@ func main() {
zero.Run(zero.Config{
NickName: []string{"椛椛", "ATRI", "atri", "亚托莉", "アトリ"},
CommandPrefix: "/",
SuperUsers: []string{"213864964"}, // 必须修改,否则无权限
SuperUsers: os.Args[1:], // 必须修改,否则无权限
Driver: []zero.Driver{
&driver.WSClient{
Url: "ws://127.0.0.1:6700",
Expand Down
111 changes: 0 additions & 111 deletions plugin_rand_image/classify.go

This file was deleted.

102 changes: 1 addition & 101 deletions plugin_rand_image/rand_image.go
Original file line number Diff line number Diff line change
@@ -1,105 +1,5 @@
package plugin_rand_image

import (
"fmt"
"strings"
"time"

zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

var (
RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img"
BLOCK_REQUEST = false
_ "github.com/FloatTech/ZeroBot-ACGImage" //简易随机图片
)

func init() { // 插件主体
zero.OnRegex(`^设置随机图片网址(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(20).
Handle(func(ctx *zero.Ctx) {
url := ctx.State["regex_matched"].([]string)[1]
if !strings.HasPrefix(url, "http") {
ctx.Send("URL非法!")
} else {
RANDOM_API_URL = url
}
return
})
// 有保护的随机图片
zero.OnFullMatch("随机图片").SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
if ctx.Event.GroupID > 0 {
Classify(ctx, RANDOM_API_URL, false)
}
return
})
// 直接随机图片,危险,仅管理员可用
zero.OnFullMatch("直接随机", zero.AdminPermission).SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
if ctx.Event.GroupID > 0 {
if BLOCK_REQUEST {
ctx.Send("请稍后再试哦")
} else {
BLOCK_REQUEST = true
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
}
}
return
})
// 撤回最后的随机图片
zero.OnFullMatch("不许好").SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
Vote(ctx, 5)
})
// 撤回最后的随机图片
zero.OnFullMatch("太涩了").SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
Vote(ctx, 6)
})
// 上传一张图进行评价
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
})

}
2 changes: 1 addition & 1 deletion plugin_setutime/setu_geter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewPools() *Pool {
Pool: map[string][]*pixiv.Illust{},
Form: 0,
}
err := os.MkdirAll(cache.Path, 0644)
err := os.MkdirAll(cache.Path, 0755)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 60dbd0d

Please sign in to comment.