mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 11:33:48 +08:00
drop cache file .cqimg.
This commit is contained in:
parent
84488f9bf1
commit
4c8b2e9f13
104
coolq/cqcode.go
104
coolq/cqcode.go
@ -1147,72 +1147,50 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
|||||||
exist = true
|
exist = true
|
||||||
rawPath = path.Join(global.ImagePathOld, f)
|
rawPath = path.Join(global.ImagePathOld, f)
|
||||||
}
|
}
|
||||||
if !exist && global.PathExists(rawPath+".cqimg") {
|
if !exist {
|
||||||
exist = true
|
if d["url"] != "" {
|
||||||
rawPath += ".cqimg"
|
return bot.makeImageOrVideoElem(map[string]string{"file": d["url"]}, false, group)
|
||||||
|
}
|
||||||
|
return nil, errors.New("invalid image")
|
||||||
}
|
}
|
||||||
if !exist && d["url"] != "" {
|
if path.Ext(rawPath) != ".image" {
|
||||||
return bot.makeImageOrVideoElem(map[string]string{"file": d["url"]}, false, group)
|
return &LocalImageElement{File: rawPath}, nil
|
||||||
}
|
}
|
||||||
if exist {
|
b, err := os.ReadFile(rawPath)
|
||||||
if path.Ext(rawPath) != ".image" && path.Ext(rawPath) != ".cqimg" {
|
if err != nil {
|
||||||
return &LocalImageElement{File: rawPath}, nil
|
return nil, err
|
||||||
}
|
|
||||||
b, err := os.ReadFile(rawPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(b) < 20 {
|
|
||||||
return nil, errors.New("invalid local file")
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
size int32
|
|
||||||
hash []byte
|
|
||||||
imageURL string
|
|
||||||
)
|
|
||||||
if path.Ext(rawPath) == ".cqimg" {
|
|
||||||
for _, line := range strings.Split(global.ReadAllText(rawPath), "\n") {
|
|
||||||
kv := strings.SplitN(line, "=", 2)
|
|
||||||
switch kv[0] {
|
|
||||||
case "md5":
|
|
||||||
hash, _ = hex.DecodeString(strings.ReplaceAll(kv[1], "\r", ""))
|
|
||||||
case "size":
|
|
||||||
t, _ := strconv.Atoi(strings.ReplaceAll(kv[1], "\r", ""))
|
|
||||||
size = int32(t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
r := binary.NewReader(b)
|
|
||||||
hash = r.ReadBytes(16)
|
|
||||||
size = r.ReadInt32()
|
|
||||||
r.ReadString()
|
|
||||||
imageURL = r.ReadString()
|
|
||||||
}
|
|
||||||
if size == 0 {
|
|
||||||
if imageURL != "" {
|
|
||||||
return bot.makeImageOrVideoElem(map[string]string{"file": imageURL}, false, group)
|
|
||||||
}
|
|
||||||
return nil, errors.New("img size is 0")
|
|
||||||
}
|
|
||||||
if len(hash) != 16 {
|
|
||||||
return nil, errors.New("invalid hash")
|
|
||||||
}
|
|
||||||
var rsp message.IMessageElement
|
|
||||||
if group {
|
|
||||||
rsp, err = bot.Client.QueryGroupImage(int64(rand.Uint32()), hash, size)
|
|
||||||
goto ok
|
|
||||||
}
|
|
||||||
rsp, err = bot.Client.QueryFriendImage(int64(rand.Uint32()), hash, size)
|
|
||||||
ok:
|
|
||||||
if err != nil {
|
|
||||||
if imageURL != "" {
|
|
||||||
return bot.makeImageOrVideoElem(map[string]string{"file": imageURL}, false, group)
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rsp, nil
|
|
||||||
}
|
}
|
||||||
return nil, errors.New("invalid image")
|
if len(b) < 20 {
|
||||||
|
return nil, errors.New("invalid local file")
|
||||||
|
}
|
||||||
|
r := binary.NewReader(b)
|
||||||
|
hash := r.ReadBytes(16)
|
||||||
|
size := r.ReadInt32()
|
||||||
|
r.ReadString()
|
||||||
|
imageURL := r.ReadString()
|
||||||
|
if size == 0 {
|
||||||
|
if imageURL != "" {
|
||||||
|
return bot.makeImageOrVideoElem(map[string]string{"file": imageURL}, false, group)
|
||||||
|
}
|
||||||
|
return nil, errors.New("img size is 0")
|
||||||
|
}
|
||||||
|
if len(hash) != 16 {
|
||||||
|
return nil, errors.New("invalid hash")
|
||||||
|
}
|
||||||
|
var rsp message.IMessageElement
|
||||||
|
if group {
|
||||||
|
rsp, err = bot.Client.QueryGroupImage(int64(rand.Uint32()), hash, size)
|
||||||
|
goto ok
|
||||||
|
}
|
||||||
|
rsp, err = bot.Client.QueryFriendImage(int64(rand.Uint32()), hash, size)
|
||||||
|
ok:
|
||||||
|
if err != nil {
|
||||||
|
if imageURL != "" {
|
||||||
|
return bot.makeImageOrVideoElem(map[string]string{"file": imageURL}, false, group)
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return rsp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// makeShowPic 一种xml 方式发送的群消息图片
|
// makeShowPic 一种xml 方式发送的群消息图片
|
||||||
|
Loading…
x
Reference in New Issue
Block a user