From bf6180a0ac18d18b7784ff6a8c34df875a229197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 4 Jun 2021 14:11:04 +0800 Subject: [PATCH 1/3] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4e36dd9d..652961fe 100644 --- a/README.md +++ b/README.md @@ -55,14 +55,18 @@ - [ ] 警告[@xxx] - [x] run[xxx] - 涩图 `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime"` - - [x] 搜索图片[P站图片ID] - - [x] 搜索图片[图片] - [x] 来份[涩图/二次元/风景/车万] - [x] 添加[涩图/二次元/风景/车万][P站图片ID] - [x] 删除[涩图/二次元/风景/车万][P站图片ID] - [x] >setu status - [x] >setu xml - [x] >setu pic +- 搜图 `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher"` + - [x] 以图搜图|搜索图片|以图识图[图片] + - [x] 搜图[P站图片ID] +- 简易随机图片(调用url) `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg"` + - [x] 随机图片 + - [x] 设置随机图片网址[url] - 点歌 `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/music"` - [x] 点歌[xxx] - [x] 网易点歌[xxx] From b7620460d3df7b89ec15652aa0ed0549eef2eb25 Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 4 Jun 2021 14:26:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8C=89id=E6=90=9C?= =?UTF-8?q?=E5=9B=BE=E6=97=B6=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/pixiv/download.go | 17 +++++++++++++++++ main.go | 7 ++++--- picsearcher/pic_searcher.go | 13 ++++++------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/api/pixiv/download.go b/api/pixiv/download.go index 3640e86b..68abb1c8 100644 --- a/api/pixiv/download.go +++ b/api/pixiv/download.go @@ -71,3 +71,20 @@ func PicHash(path string) string { } return strings.ToUpper(fmt.Sprintf("%x", md5.Sum(data))) } + +// urlCache 缓存并返回缓存路径 +func (this *Illust) RmPic(path string) (err error) { + url := this.ImageUrls + pid := this.Pid + url = strings.ReplaceAll(url, "img-original", "img-master") + url = strings.ReplaceAll(url, "_p0", "_p0_master1200") + url = strings.ReplaceAll(url, ".png", ".jpg") + // 文件名为url的hash值 + savePath := path + Int2Str(pid) + ".jpg" + // 文件存在或文件大小大于10kb + if PathExists(savePath) { + return os.Remove(savePath) + } else { + return nil + } +} diff --git a/main.go b/main.go index a431de5f..4abe9e59 100644 --- a/main.go +++ b/main.go @@ -26,8 +26,9 @@ import ( _ "github.com/Yiwen-Chan/ZeroBot-Plugin/music" // 点歌 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher" // 搜图 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 + + //_ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 ) func init() { @@ -52,7 +53,7 @@ func main() { CommandPrefix: "/", SuperUsers: os.Args[1:], // 必须修改,否则无权限 Driver: []zero.Driver{ - driver.NewWebSocketClient("127.0.0.1", "6700", ""), + driver.NewWebSocketClient("192.168.8.1", "6700", ""), }, }) // 帮助 diff --git a/picsearcher/pic_searcher.go b/picsearcher/pic_searcher.go index 09904be3..287e3548 100644 --- a/picsearcher/pic_searcher.go +++ b/picsearcher/pic_searcher.go @@ -13,13 +13,10 @@ import ( utils "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher/utils" ) -var ( - BOTPATH = pixiv.PathExecute() // 当前bot运行目录 - DATAPATH = BOTPATH + "data/SetuTime/" // 数据目录 - CACHEPATH = DATAPATH + "cache/" // 缓冲图片路径 -) +var CACHEPATH = "/tmp/picsch/" // 缓冲图片路径 func init() { // 插件主体 + pixiv.CreatePath(CACHEPATH) // 根据PID搜图 zero.OnRegex(`^搜图(\d+)$`).SetBlock(true).SetPriority(30). Handle(func(ctx *zero.Ctx) { @@ -32,12 +29,14 @@ func init() { // 插件主体 return } // 下载P站插图 - if _, err := illust.PixivPicDown(CACHEPATH); err != nil { + savePath, err := illust.PixivPicDown(CACHEPATH) + if err != nil { ctx.Send(fmt.Sprintf("ERROR: %v", err)) return } // 发送搜索结果 - ctx.Send(illust.DetailPic) + ctx.Send(illust.DetailPic(savePath)) + illust.RmPic(CACHEPATH) return }) // 以图搜图 From 0595fb223ae773d18988871ad6dbb939ffe46ac7 Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 4 Jun 2021 14:27:22 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=81=A2=E5=A4=8Dmain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 4abe9e59..e6fbb5ae 100644 --- a/main.go +++ b/main.go @@ -27,8 +27,8 @@ import ( _ "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher" // 搜图 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片 - //_ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 ) func init() { @@ -53,7 +53,7 @@ func main() { CommandPrefix: "/", SuperUsers: os.Args[1:], // 必须修改,否则无权限 Driver: []zero.Driver{ - driver.NewWebSocketClient("192.168.8.1", "6700", ""), + driver.NewWebSocketClient("127.0.0.1", "6700", ""), }, }) // 帮助