Merge pull request #25 from fumiama/master

修复按id搜图时失败、更新README
This commit is contained in:
Kanri 2021-06-05 03:13:29 -05:00 committed by GitHub
commit 0ba5aedd2d
4 changed files with 32 additions and 11 deletions

View File

@ -55,14 +55,18 @@
- [ ] 警告[@xxx] - [ ] 警告[@xxx]
- [x] run[xxx] - [x] run[xxx]
- 涩图 `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime"` - 涩图 `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime"`
- [x] 搜索图片[P站图片ID]
- [x] 搜索图片[图片]
- [x] 来份[涩图/二次元/风景/车万] - [x] 来份[涩图/二次元/风景/车万]
- [x] 添加[涩图/二次元/风景/车万][P站图片ID] - [x] 添加[涩图/二次元/风景/车万][P站图片ID]
- [x] 删除[涩图/二次元/风景/车万][P站图片ID] - [x] 删除[涩图/二次元/风景/车万][P站图片ID]
- [x] >setu status - [x] >setu status
- [x] >setu xml - [x] >setu xml
- [x] >setu pic - [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"` - 点歌 `import _ "github.com/Yiwen-Chan/ZeroBot-Plugin/music"`
- [x] 点歌[xxx] - [x] 点歌[xxx]
- [x] 网易点歌[xxx] - [x] 网易点歌[xxx]

View File

@ -71,3 +71,20 @@ func PicHash(path string) string {
} }
return strings.ToUpper(fmt.Sprintf("%x", md5.Sum(data))) 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
}
}

View File

@ -26,6 +26,7 @@ import (
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/music" // 点歌 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/music" // 点歌
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher" // 搜图 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher" // 搜图
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图
_ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定
) )

View File

@ -13,13 +13,10 @@ import (
utils "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher/utils" utils "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher/utils"
) )
var ( var CACHEPATH = "/tmp/picsch/" // 缓冲图片路径
BOTPATH = pixiv.PathExecute() // 当前bot运行目录
DATAPATH = BOTPATH + "data/SetuTime/" // 数据目录
CACHEPATH = DATAPATH + "cache/" // 缓冲图片路径
)
func init() { // 插件主体 func init() { // 插件主体
pixiv.CreatePath(CACHEPATH)
// 根据PID搜图 // 根据PID搜图
zero.OnRegex(`^搜图(\d+)$`).SetBlock(true).SetPriority(30). zero.OnRegex(`^搜图(\d+)$`).SetBlock(true).SetPriority(30).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
@ -32,12 +29,14 @@ func init() { // 插件主体
return return
} }
// 下载P站插图 // 下载P站插图
if _, err := illust.PixivPicDown(CACHEPATH); err != nil { savePath, err := illust.PixivPicDown(CACHEPATH)
if err != nil {
ctx.Send(fmt.Sprintf("ERROR: %v", err)) ctx.Send(fmt.Sprintf("ERROR: %v", err))
return return
} }
// 发送搜索结果 // 发送搜索结果
ctx.Send(illust.DetailPic) ctx.Send(illust.DetailPic(savePath))
illust.RmPic(CACHEPATH)
return return
}) })
// 以图搜图 // 以图搜图