mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 12:03:50 +08:00
optimize get_image
This commit is contained in:
parent
223a888a34
commit
f86947a8df
@ -952,9 +952,11 @@ func (bot *CQBot) CQGetImage(file string) MSG {
|
||||
}
|
||||
local := path.Join(global.CachePath, file+"."+path.Ext(msg["filename"].(string)))
|
||||
if !global.PathExists(local) {
|
||||
if data, err := global.GetBytes(msg["url"].(string)); err == nil {
|
||||
_ = ioutil.WriteFile(local, data, 0o644)
|
||||
f, _ := os.OpenFile(local, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o0644)
|
||||
if body, err := global.HTTPGetReadCloser(msg["url"].(string)); err != nil {
|
||||
_, _ = f.ReadFrom(body)
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
msg["file"] = local
|
||||
return OK(msg)
|
||||
|
18
coolq/bot.go
18
coolq/bot.go
@ -371,7 +371,11 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
||||
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||
return -1
|
||||
}
|
||||
if err := bot.db.Put(binary.ToBytes(id), binary.GZipCompress(buf.Bytes()), nil); err != nil {
|
||||
gw := binary.AcquireGzipWriter()
|
||||
defer binary.ReleaseGzipWriter(gw)
|
||||
_, _ = gw.Write(buf.Bytes())
|
||||
_ = gw.Close()
|
||||
if err := bot.db.Put(binary.ToBytes(id), gw.Bytes(), nil); err != nil {
|
||||
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||
return -1
|
||||
}
|
||||
@ -397,7 +401,11 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
||||
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||
return -1
|
||||
}
|
||||
if err := bot.db.Put(binary.ToBytes(id), binary.GZipCompress(buf.Bytes()), nil); err != nil {
|
||||
gw := binary.AcquireGzipWriter()
|
||||
defer binary.ReleaseGzipWriter(gw)
|
||||
_, _ = gw.Write(buf.Bytes())
|
||||
_ = gw.Close()
|
||||
if err := bot.db.Put(binary.ToBytes(id), gw.Bytes(), nil); err != nil {
|
||||
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||
return -1
|
||||
}
|
||||
@ -425,7 +433,11 @@ func (bot *CQBot) InsertTempMessage(target int64, m *message.TempMessage) int32
|
||||
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||
return -1
|
||||
}
|
||||
if err := bot.db.Put(binary.ToBytes(id), binary.GZipCompress(buf.Bytes()), nil); err != nil {
|
||||
gw := binary.AcquireGzipWriter()
|
||||
defer binary.ReleaseGzipWriter(gw)
|
||||
_, _ = gw.Write(buf.Bytes())
|
||||
_ = gw.Close()
|
||||
if err := bot.db.Put(binary.ToBytes(id), gw.Bytes(), nil); err != nil {
|
||||
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||
return -1
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user