mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-07 20:45:53 +08:00
update MiraiGo.
This commit is contained in:
parent
b8916d2570
commit
773952d6d6
24
coolq/bot.go
24
coolq/bot.go
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
@ -118,11 +119,30 @@ func (bot *CQBot) GetMessage(mid int32) MSG {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElement) (*message.GroupImageElement, error) {
|
||||||
|
if img.Stream != nil {
|
||||||
|
return bot.Client.UploadGroupImage(groupCode, img.Stream)
|
||||||
|
}
|
||||||
|
return bot.Client.UploadGroupImageByFile(groupCode, img.File)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) UploadLocalImageAsPrivate(userId int64, img *LocalImageElement) (*message.FriendImageElement, error) {
|
||||||
|
if img.Stream != nil {
|
||||||
|
return bot.Client.UploadPrivateImage(userId, img.Stream)
|
||||||
|
}
|
||||||
|
// need update.
|
||||||
|
f, err := os.Open(img.File)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return bot.Client.UploadPrivateImage(userId, f)
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int32 {
|
func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int32 {
|
||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
for _, elem := range m.Elements {
|
for _, elem := range m.Elements {
|
||||||
if i, ok := elem.(*LocalImageElement); ok {
|
if i, ok := elem.(*LocalImageElement); ok {
|
||||||
gm, err := bot.Client.UploadGroupImage(groupId, i.Stream)
|
gm, err := bot.UploadLocalImageAsGroup(groupId, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 群 %v 消息图片上传失败: %v", groupId, err)
|
log.Warnf("警告: 群 %v 消息图片上传失败: %v", groupId, err)
|
||||||
continue
|
continue
|
||||||
@ -238,7 +258,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
|
|||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
for _, elem := range m.Elements {
|
for _, elem := range m.Elements {
|
||||||
if i, ok := elem.(*LocalImageElement); ok {
|
if i, ok := elem.(*LocalImageElement); ok {
|
||||||
fm, err := bot.Client.UploadPrivateImage(target, i.Stream)
|
fm, err := bot.UploadLocalImageAsPrivate(target, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 私聊 %v 消息图片上传失败.", target)
|
log.Warnf("警告: 私聊 %v 消息图片上传失败.", target)
|
||||||
continue
|
continue
|
||||||
|
@ -69,6 +69,7 @@ type MiguMusicElement struct {
|
|||||||
type LocalImageElement struct {
|
type LocalImageElement struct {
|
||||||
message.ImageElement
|
message.ImageElement
|
||||||
Stream io.ReadSeeker
|
Stream io.ReadSeeker
|
||||||
|
File string
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalVoiceElement struct {
|
type LocalVoiceElement struct {
|
||||||
@ -556,9 +557,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
}
|
}
|
||||||
if i, ok := img.(*LocalImageElement); ok { // 秀图,闪照什么的就直接传了吧
|
if i, ok := img.(*LocalImageElement); ok { // 秀图,闪照什么的就直接传了吧
|
||||||
if group {
|
if group {
|
||||||
img, err = bot.Client.UploadGroupImage(1, i.Stream)
|
img, err = bot.UploadLocalImageAsGroup(1, i)
|
||||||
} else {
|
} else {
|
||||||
img, err = bot.Client.UploadPrivateImage(1, i.Stream)
|
img, err = bot.UploadLocalImageAsPrivate(1, i)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -826,10 +827,7 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
|||||||
hash := md5.Sum([]byte(f))
|
hash := md5.Sum([]byte(f))
|
||||||
cacheFile := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".cache")
|
cacheFile := path.Join(global.CACHE_PATH, hex.EncodeToString(hash[:])+".cache")
|
||||||
if global.PathExists(cacheFile) && cache == "1" {
|
if global.PathExists(cacheFile) && cache == "1" {
|
||||||
f, err := os.Open(cacheFile)
|
return &LocalImageElement{File: cacheFile}, nil
|
||||||
if err == nil {
|
|
||||||
return &LocalImageElement{Stream: f}, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if global.PathExists(cacheFile) {
|
if global.PathExists(cacheFile) {
|
||||||
_ = os.Remove(cacheFile)
|
_ = os.Remove(cacheFile)
|
||||||
@ -838,11 +836,7 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
|||||||
if err := global.DownloadFileMultiThreading(f, cacheFile, maxImageSize, thread); err != nil {
|
if err := global.DownloadFileMultiThreading(f, cacheFile, maxImageSize, thread); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f, err := os.Open(cacheFile)
|
return &LocalImageElement{File: cacheFile}, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LocalImageElement{Stream: f}, nil
|
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(f, "base64") {
|
if strings.HasPrefix(f, "base64") {
|
||||||
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
||||||
@ -866,11 +860,7 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
|||||||
if info.Size() == 0 || info.Size() >= maxImageSize {
|
if info.Size() == 0 || info.Size() >= maxImageSize {
|
||||||
return nil, errors.New("invalid image size")
|
return nil, errors.New("invalid image size")
|
||||||
}
|
}
|
||||||
file, err := os.Open(fu.Path)
|
return &LocalImageElement{File: fu.Path}, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &LocalImageElement{Stream: file}, nil
|
|
||||||
}
|
}
|
||||||
rawPath := path.Join(global.IMAGE_PATH, f)
|
rawPath := path.Join(global.IMAGE_PATH, f)
|
||||||
if !global.PathExists(rawPath) && global.PathExists(path.Join(global.IMAGE_PATH_OLD, f)) {
|
if !global.PathExists(rawPath) && global.PathExists(path.Join(global.IMAGE_PATH_OLD, f)) {
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
|||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210102161828-e1e1c97a56f2
|
github.com/Mrs4s/MiraiGo v0.0.0-20210104164708-e94ea61cc8e9
|
||||||
github.com/dustin/go-humanize v1.0.0
|
github.com/dustin/go-humanize v1.0.0
|
||||||
github.com/gin-contrib/pprof v1.3.0
|
github.com/gin-contrib/pprof v1.3.0
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
|
7
go.sum
7
go.sum
@ -1,9 +1,7 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210102160857-d0a296aab77f h1:Cup2n0Da+Iy9p0Jpgi/KxjvlCHwBZzfY4YB13l4mFLk=
|
github.com/Mrs4s/MiraiGo v0.0.0-20210104164708-e94ea61cc8e9 h1:jzaBgDPLKRuJxQO9UT/2vCFL0ScCO9IThRCa7ViMbGE=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210102160857-d0a296aab77f/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
|
github.com/Mrs4s/MiraiGo v0.0.0-20210104164708-e94ea61cc8e9/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210102161828-e1e1c97a56f2 h1:7tuZag+0XUisdi3HJq5iaSGIJ3Q0doa2leSl1iH3cKs=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210102161828-e1e1c97a56f2/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
|
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -54,7 +52,6 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
|
|||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/guonaihong/gout v0.1.4 h1:uBBoyztMX9okC27OQxqhn6bZ0ROkGyvnEIHwtp3TM4g=
|
github.com/guonaihong/gout v0.1.4 h1:uBBoyztMX9okC27OQxqhn6bZ0ROkGyvnEIHwtp3TM4g=
|
||||||
github.com/guonaihong/gout v0.1.4/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic=
|
github.com/guonaihong/gout v0.1.4/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic=
|
||||||
github.com/hjson/hjson-go v0.2.3 h1:KhG7/PSxTibbYOzFso5FoiX2gWePcANaCsvM1WE/bTo=
|
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
|
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user