1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-19 14:05:03 +08:00

remove message.ShortVideoElement in LocalVideoElement

This commit is contained in:
wdvxdr 2021-08-09 21:14:36 +08:00
parent 5b705273c2
commit 84488f9bf1
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
2 changed files with 20 additions and 16 deletions

View File

@ -212,7 +212,6 @@ func (bot *CQBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElemen
// UploadLocalVideo 上传本地短视频至群聊 // UploadLocalVideo 上传本地短视频至群聊
func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message.ShortVideoElement, error) { func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message.ShortVideoElement, error) {
if v.File != "" {
video, err := os.Open(v.File) video, err := os.Open(v.File)
if err != nil { if err != nil {
return nil, err return nil, err
@ -223,8 +222,6 @@ func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message
_, _ = video.Seek(0, io.SeekStart) _, _ = video.Seek(0, io.SeekStart)
_, _ = v.thumb.Seek(0, io.SeekStart) _, _ = v.thumb.Seek(0, io.SeekStart)
return bot.Client.UploadGroupShortVideo(target, video, v.thumb, cacheFile) return bot.Client.UploadGroupShortVideo(target, video, v.thumb, cacheFile)
}
return &v.ShortVideoElement, nil
} }
// UploadLocalImageAsPrivate 上传本地图片至私聊 // UploadLocalImageAsPrivate 上传本地图片至私聊

View File

@ -81,7 +81,6 @@ type LocalVoiceElement struct {
// LocalVideoElement 本地视频 // LocalVideoElement 本地视频
type LocalVideoElement struct { type LocalVideoElement struct {
message.ShortVideoElement
File string File string
thumb io.ReadSeeker thumb io.ReadSeeker
} }
@ -97,6 +96,11 @@ func (e *GiftElement) Type() message.ElementType {
return message.At return message.At
} }
// Type impl message.IMessageElement
func (e *LocalVideoElement) Type() message.ElementType {
return message.Video
}
// GiftID 礼物ID数组 // GiftID 礼物ID数组
var GiftID = [...]message.GroupGift{ var GiftID = [...]message.GroupGift{
message.SweetWink, message.SweetWink,
@ -902,7 +906,10 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
if err != nil { if err != nil {
return nil, err return nil, err
} }
v := file.(*LocalVideoElement) v, ok := file.(*LocalVideoElement)
if !ok {
return file, nil
}
if v.File == "" { if v.File == "" {
return v, nil return v, nil
} }
@ -1124,14 +1131,14 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
if path.Ext(rawPath) == ".video" { if path.Ext(rawPath) == ".video" {
b, _ := os.ReadFile(rawPath) b, _ := os.ReadFile(rawPath)
r := binary.NewReader(b) r := binary.NewReader(b)
return &LocalVideoElement{ShortVideoElement: message.ShortVideoElement{ // todo 检查缓存是否有效 return &message.ShortVideoElement{ // todo 检查缓存是否有效
Md5: r.ReadBytes(16), Md5: r.ReadBytes(16),
ThumbMd5: r.ReadBytes(16), ThumbMd5: r.ReadBytes(16),
Size: r.ReadInt32(), Size: r.ReadInt32(),
ThumbSize: r.ReadInt32(), ThumbSize: r.ReadInt32(),
Name: r.ReadString(), Name: r.ReadString(),
Uuid: r.ReadAvailable(), Uuid: r.ReadAvailable(),
}}, nil }, nil
} }
return &LocalVideoElement{File: rawPath}, nil return &LocalVideoElement{File: rawPath}, nil
} }