|
7 | 7 |
|
8 | 8 | "github.com/Mrs4s/MiraiGo/client" |
9 | 9 | "github.com/Mrs4s/MiraiGo/message" |
| 10 | + "github.com/ProtobufBot/Go-Mirai-Client/pkg/clz" |
10 | 11 | "github.com/ProtobufBot/Go-Mirai-Client/pkg/util" |
11 | 12 | "github.com/ProtobufBot/Go-Mirai-Client/proto_gen/onebot" |
12 | 13 | "github.com/ProtobufBot/Go-Mirai-Client/service/cache" |
@@ -59,6 +60,8 @@ func ProtoMsgToMiraiMsg(cli *client.QQClient, msgList []*onebot.Message, notConv |
59 | 60 | ProtoSleep(protoMsg.Data) |
60 | 61 | case "tts": |
61 | 62 | messageChain = append(messageChain, ProtoTtsToMiraiTts(cli, protoMsg.Data)) |
| 63 | + case "video": |
| 64 | + messageChain = append(messageChain, ProtoVideoToMiraiVideo(cli, protoMsg.Data)) |
62 | 65 | default: |
63 | 66 | log.Errorf("不支持的消息类型 %+v", protoMsg) |
64 | 67 | } |
@@ -297,3 +300,33 @@ func ProtoTtsToMiraiTts(cli *client.QQClient, data map[string]string) (m message |
297 | 300 | } |
298 | 301 | return &message.VoiceElement{Data: b} |
299 | 302 | } |
| 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 | +} |
0 commit comments