Skip to content

Commit

Permalink
修复按id搜图时失败
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jun 4, 2021
1 parent 3e3e200 commit 2f0510f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
17 changes: 17 additions & 0 deletions api/pixiv/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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", ""),
},
})
// 帮助
Expand Down
13 changes: 6 additions & 7 deletions picsearcher/pic_searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
})
// 以图搜图
Expand Down

0 comments on commit 2f0510f

Please sign in to comment.