Skip to content

Commit 696f125

Browse files
committed
send group video
1 parent 0ac6c91 commit 696f125

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ require (
2525
gopkg.in/yaml.v2 v2.4.0
2626
)
2727

28-
replace github.com/Mrs4s/MiraiGo => ../../Mrs4s/MiraiGo
28+
//replace github.com/Mrs4s/MiraiGo => ../../Mrs4s/MiraiGo

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ github.com/Mrs4s/MiraiGo v0.0.0-20210107163750-ce4834c2ba71 h1:WAVoBY4G2BC5Dyw1A
4646
github.com/Mrs4s/MiraiGo v0.0.0-20210107163750-ce4834c2ba71/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
4747
github.com/Mrs4s/MiraiGo v0.0.0-20210108093149-f40ac95fffa4 h1:1AEB2CdtzpDjQzpQFGVjV203ybjCSaqo/gmKdYmr8Jo=
4848
github.com/Mrs4s/MiraiGo v0.0.0-20210108093149-f40ac95fffa4/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
49+
github.com/Mrs4s/MiraiGo v0.0.0-20210110160231-b83dd4cf38a5 h1:ee6LafOcoVM0nox2UxiIJgomgRP4pDJe5aeT/rq2o/U=
50+
github.com/Mrs4s/MiraiGo v0.0.0-20210110160231-b83dd4cf38a5/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
4951
github.com/a8m/syncmap v0.0.0-20200818084611-4bbbd178de97/go.mod h1:f3iF7/3t9i9hsYF8DPgT0XeIVyNzevhMCKf2445Q6pE=
5052
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5153
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=

pkg/clz/clz.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package clz
2+
3+
import "github.com/Mrs4s/MiraiGo/message"
4+
5+
// 自定义类型
6+
7+
type VideoElement struct {
8+
message.ShortVideoElement
9+
UploadingCoverBytes []byte // 待上传的封面
10+
UploadingVideoBytes []byte // 待上传的视频
11+
}

service/bot/api_handler.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package bot
22

33
import (
44
"bytes"
5+
"github.com/ProtobufBot/Go-Mirai-Client/pkg/clz"
56
"math"
67
"strconv"
78

@@ -102,6 +103,15 @@ func preProcessGroupSendingMessage(cli *client.QQClient, groupCode int64, m *mes
102103
newElements = append(newElements, i)
103104
continue
104105
}
106+
if i, ok := element.(*clz.VideoElement); ok {
107+
gm, err := cli.UploadGroupShortVideo(groupCode, bytes.NewReader(i.UploadingVideoBytes), bytes.NewReader(i.UploadingCoverBytes))
108+
if err != nil {
109+
log.Errorf("failed to upload group video, %+v", err)
110+
continue
111+
}
112+
newElements = append(newElements, gm)
113+
continue
114+
}
105115
newElements = append(newElements, element)
106116
}
107117
m.Elements = newElements

service/bot/proto2mirai.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/Mrs4s/MiraiGo/client"
99
"github.com/Mrs4s/MiraiGo/message"
10+
"github.com/ProtobufBot/Go-Mirai-Client/pkg/clz"
1011
"github.com/ProtobufBot/Go-Mirai-Client/pkg/util"
1112
"github.com/ProtobufBot/Go-Mirai-Client/proto_gen/onebot"
1213
"github.com/ProtobufBot/Go-Mirai-Client/service/cache"
@@ -59,6 +60,8 @@ func ProtoMsgToMiraiMsg(cli *client.QQClient, msgList []*onebot.Message, notConv
5960
ProtoSleep(protoMsg.Data)
6061
case "tts":
6162
messageChain = append(messageChain, ProtoTtsToMiraiTts(cli, protoMsg.Data))
63+
case "video":
64+
messageChain = append(messageChain, ProtoVideoToMiraiVideo(cli, protoMsg.Data))
6265
default:
6366
log.Errorf("不支持的消息类型 %+v", protoMsg)
6467
}
@@ -297,3 +300,33 @@ func ProtoTtsToMiraiTts(cli *client.QQClient, data map[string]string) (m message
297300
}
298301
return &message.VoiceElement{Data: b}
299302
}
303+
304+
func ProtoVideoToMiraiVideo(cli *client.QQClient, data map[string]string) (m message.IMessageElement) {
305+
coverUrl, ok := data["cover"]
306+
if !ok {
307+
log.Warnf("video cover不存在")
308+
return EmptyText()
309+
}
310+
url, ok := data["url"]
311+
if !ok || !strings.Contains(url, "http") {
312+
url, ok = data["file"]
313+
if !ok || !strings.Contains(url, "http") {
314+
log.Warnf("video url不存在")
315+
return EmptyText()
316+
}
317+
}
318+
coverBytes, err := util.GetBytes(coverUrl)
319+
if err != nil {
320+
log.Errorf("failed to download cover, err: %+v", err)
321+
return EmptyText()
322+
}
323+
videoBytes, err := util.GetBytes(url)
324+
if err != nil {
325+
log.Errorf("failed to download video, err: %+v", err)
326+
return EmptyText()
327+
}
328+
return &clz.VideoElement{
329+
UploadingCoverBytes: coverBytes,
330+
UploadingVideoBytes: videoBytes,
331+
}
332+
}

service/bot/raw2mirai.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ func RawMsgToMiraiMsg(cli *client.QQClient, str string) []message.IMessageElemen
7474
ProtoSleep(attrMap)
7575
case "tts":
7676
elemList = append(elemList, ProtoTtsToMiraiTts(cli, attrMap))
77+
case "video":
78+
elemList = append(elemList, ProtoVideoToMiraiVideo(cli, attrMap))
7779
default:
7880
log.Warnf("不支持的类型 %s", code)
7981
elemList = append(elemList, message.NewText(code))

0 commit comments

Comments
 (0)