mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-19 05:55:04 +08:00
remove message.ShortVideoElement in LocalVideoElement
This commit is contained in:
parent
5b705273c2
commit
84488f9bf1
21
coolq/bot.go
21
coolq/bot.go
@ -212,19 +212,16 @@ func (bot *CQBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElemen
|
||||
|
||||
// UploadLocalVideo 上传本地短视频至群聊
|
||||
func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message.ShortVideoElement, error) {
|
||||
if v.File != "" {
|
||||
video, err := os.Open(v.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer video.Close()
|
||||
hash, _ := utils.ComputeMd5AndLength(io.MultiReader(video, v.thumb))
|
||||
cacheFile := path.Join(global.CachePath, hex.EncodeToString(hash)+".cache")
|
||||
_, _ = video.Seek(0, io.SeekStart)
|
||||
_, _ = v.thumb.Seek(0, io.SeekStart)
|
||||
return bot.Client.UploadGroupShortVideo(target, video, v.thumb, cacheFile)
|
||||
video, err := os.Open(v.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v.ShortVideoElement, nil
|
||||
defer video.Close()
|
||||
hash, _ := utils.ComputeMd5AndLength(io.MultiReader(video, v.thumb))
|
||||
cacheFile := path.Join(global.CachePath, hex.EncodeToString(hash)+".cache")
|
||||
_, _ = video.Seek(0, io.SeekStart)
|
||||
_, _ = v.thumb.Seek(0, io.SeekStart)
|
||||
return bot.Client.UploadGroupShortVideo(target, video, v.thumb, cacheFile)
|
||||
}
|
||||
|
||||
// UploadLocalImageAsPrivate 上传本地图片至私聊
|
||||
|
@ -81,7 +81,6 @@ type LocalVoiceElement struct {
|
||||
|
||||
// LocalVideoElement 本地视频
|
||||
type LocalVideoElement struct {
|
||||
message.ShortVideoElement
|
||||
File string
|
||||
thumb io.ReadSeeker
|
||||
}
|
||||
@ -97,6 +96,11 @@ func (e *GiftElement) Type() message.ElementType {
|
||||
return message.At
|
||||
}
|
||||
|
||||
// Type impl message.IMessageElement
|
||||
func (e *LocalVideoElement) Type() message.ElementType {
|
||||
return message.Video
|
||||
}
|
||||
|
||||
// GiftID 礼物ID数组
|
||||
var GiftID = [...]message.GroupGift{
|
||||
message.SweetWink,
|
||||
@ -902,7 +906,10 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v := file.(*LocalVideoElement)
|
||||
v, ok := file.(*LocalVideoElement)
|
||||
if !ok {
|
||||
return file, nil
|
||||
}
|
||||
if v.File == "" {
|
||||
return v, nil
|
||||
}
|
||||
@ -1124,14 +1131,14 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
||||
if path.Ext(rawPath) == ".video" {
|
||||
b, _ := os.ReadFile(rawPath)
|
||||
r := binary.NewReader(b)
|
||||
return &LocalVideoElement{ShortVideoElement: message.ShortVideoElement{ // todo 检查缓存是否有效
|
||||
return &message.ShortVideoElement{ // todo 检查缓存是否有效
|
||||
Md5: r.ReadBytes(16),
|
||||
ThumbMd5: r.ReadBytes(16),
|
||||
Size: r.ReadInt32(),
|
||||
ThumbSize: r.ReadInt32(),
|
||||
Name: r.ReadString(),
|
||||
Uuid: r.ReadAvailable(),
|
||||
}}, nil
|
||||
}, nil
|
||||
}
|
||||
return &LocalVideoElement{File: rawPath}, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user