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:
parent
06f4a10cf7
commit
2ec7f83d38
@ -2,6 +2,7 @@ package coolq
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"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 {
|
if len(b) < 20 {
|
||||||
return nil, errors.New("invalid local file")
|
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)
|
r := binary.NewReader(b)
|
||||||
hash := r.ReadBytes(16)
|
hash = r.ReadBytes(16)
|
||||||
|
size = r.ReadInt32()
|
||||||
|
}
|
||||||
if group {
|
if group {
|
||||||
rsp, err := bot.Client.QueryGroupImage(1, hash, r.ReadInt32())
|
rsp, err := bot.Client.QueryGroupImage(1, hash, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return rsp, nil
|
return rsp, nil
|
||||||
}
|
}
|
||||||
rsp, err := bot.Client.QueryFriendImage(1, hash, r.ReadInt32())
|
rsp, err := bot.Client.QueryFriendImage(1, hash, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
2
main.go
2
main.go
@ -184,7 +184,7 @@ func main() {
|
|||||||
log.Info("アトリは、高性能ですから!")
|
log.Info("アトリは、高性能ですから!")
|
||||||
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
|
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
|
||||||
if conf.ReLogin {
|
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))
|
time.Sleep(time.Second * time.Duration(conf.ReLoginDelay))
|
||||||
rsp, err := cli.Login()
|
rsp, err := cli.Login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user