1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

supported .cqimg direct sending.

This commit is contained in:
Mrs4s 2020-08-07 13:56:56 +08:00
parent 06f4a10cf7
commit 2ec7f83d38
2 changed files with 22 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package coolq
import (
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"github.com/Mrs4s/MiraiGo/binary"
@ -204,16 +205,32 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
if len(b) < 20 {
return nil, errors.New("invalid local file")
}
var size int32
var hash []byte
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(kv[1])
case "size":
t, _ := strconv.Atoi(kv[1])
size = int32(t)
}
}
} else {
r := binary.NewReader(b)
hash := r.ReadBytes(16)
hash = r.ReadBytes(16)
size = r.ReadInt32()
}
if group {
rsp, err := bot.Client.QueryGroupImage(1, hash, r.ReadInt32())
rsp, err := bot.Client.QueryGroupImage(1, hash, size)
if err != nil {
return nil, err
}
return rsp, nil
}
rsp, err := bot.Client.QueryFriendImage(1, hash, r.ReadInt32())
rsp, err := bot.Client.QueryFriendImage(1, hash, size)
if err != nil {
return nil, err
}

View File

@ -184,7 +184,7 @@ func main() {
log.Info("アトリは、高性能ですから!")
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
if conf.ReLogin {
log.Warnf("Bot已离线,将在 %v 秒后尝试重连.", conf.ReLoginDelay)
log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连.", e.Message, conf.ReLoginDelay)
time.Sleep(time.Second * time.Duration(conf.ReLoginDelay))
rsp, err := cli.Login()
if err != nil {