mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
✏️ 尝试解决win下路径异常
This commit is contained in:
parent
3a5e391191
commit
a3685e2e83
@ -3,7 +3,6 @@ package acgimage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -13,6 +12,7 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||||
|
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -21,9 +21,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
botpath, _ = os.Getwd()
|
datapath = file.BOT_PATH + "/data/acgimage/"
|
||||||
datapath = botpath + "/data/acgimage/"
|
cacheuri = "file:///" + datapath + "cache"
|
||||||
cacheuri = "file:///" + datapath + "cache"
|
|
||||||
// r18有一定保护,一般不会发出图片
|
// r18有一定保护,一般不会发出图片
|
||||||
randapi = "&loli=true&r18=true"
|
randapi = "&loli=true&r18=true"
|
||||||
msgof = make(map[int64]int64)
|
msgof = make(map[int64]int64)
|
||||||
|
|||||||
@ -17,8 +17,7 @@ import (
|
|||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
||||||
)
|
)
|
||||||
|
|
||||||
var botpath, _ = os.Getwd()
|
var cachedir = file.BOT_PATH + "/data/hs/"
|
||||||
var cachedir = botpath + "/data/hs/"
|
|
||||||
|
|
||||||
var header = req.Header{
|
var header = req.Header{
|
||||||
"user-agent": `Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36`,
|
"user-agent": `Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36`,
|
||||||
|
|||||||
@ -19,8 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
botpath, _ = os.Getwd()
|
datapath = file.BOT_PATH + "/data/saucenao/"
|
||||||
datapath = botpath + "/data/saucenao/"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/control"
|
"github.com/FloatTech/ZeroBot-Plugin/control"
|
||||||
|
fileutil "github.com/FloatTech/ZeroBot-Plugin/utils/file"
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/math"
|
"github.com/FloatTech/ZeroBot-Plugin/utils/math"
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
"github.com/FloatTech/ZeroBot-Plugin/utils/sql"
|
||||||
)
|
)
|
||||||
@ -249,8 +250,7 @@ func (p *imgpool) pop(imgtype string) (illust *pixiv.Illust) {
|
|||||||
|
|
||||||
func file(i *pixiv.Illust) string {
|
func file(i *pixiv.Illust) string {
|
||||||
filename := fmt.Sprint(i.Pid)
|
filename := fmt.Sprint(i.Pid)
|
||||||
pwd, _ := os.Getwd()
|
filepath := fileutil.BOT_PATH + `/` + pool.Path + filename
|
||||||
filepath := pwd + `/` + pool.Path + filename
|
|
||||||
if _, err := os.Stat(filepath + ".jpg"); err == nil || os.IsExist(err) {
|
if _, err := os.Stat(filepath + ".jpg"); err == nil || os.IsExist(err) {
|
||||||
return `file:///` + filepath + ".jpg"
|
return `file:///` + filepath + ".jpg"
|
||||||
}
|
}
|
||||||
|
|||||||
11
utils/file/dir_nowin.go
Normal file
11
utils/file/dir_nowin.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//go:build !windows
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package file
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
func Pwd() (path string) {
|
||||||
|
path, _ = os.Getwd()
|
||||||
|
return
|
||||||
|
}
|
||||||
14
utils/file/dir_win.go
Normal file
14
utils/file/dir_win.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Pwd() string {
|
||||||
|
path, _ := os.Getwd()
|
||||||
|
return strings.ReplaceAll(path, "\\", "/")
|
||||||
|
}
|
||||||
@ -21,15 +21,3 @@ func DownloadTo(url, file string) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsExist 文件/路径存在
|
|
||||||
func IsExist(path string) bool {
|
|
||||||
_, err := os.Stat(path)
|
|
||||||
return err == nil || os.IsExist(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsExist 文件/路径不存在
|
|
||||||
func IsNotExist(path string) bool {
|
|
||||||
_, err := os.Stat(path)
|
|
||||||
return err != nil && os.IsNotExist(err)
|
|
||||||
}
|
|
||||||
|
|||||||
17
utils/file/f.go
Normal file
17
utils/file/f.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package file
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
var BOT_PATH = Pwd()
|
||||||
|
|
||||||
|
// IsExist 文件/路径存在
|
||||||
|
func IsExist(path string) bool {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
return err == nil || os.IsExist(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsExist 文件/路径不存在
|
||||||
|
func IsNotExist(path string) bool {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
return err != nil && os.IsNotExist(err)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user