1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

Merge pull request #63 from wfjsw/patches/proper-flash-pic-support

proper flash pic support
This commit is contained in:
Mrs4s 2020-11-17 20:45:30 +08:00 committed by GitHub
commit 0a7e4ea557
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 17 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.idea
vendor/

View File

@ -2,10 +2,11 @@ package message
import (
"fmt"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"strconv"
"strings"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
)
type TextElement struct {
@ -113,6 +114,12 @@ type RedBagElement struct {
Title string
}
// TODO: 总之就是非常傻逼
type GroupFlashImgElement struct {
ImageElement
}
type GroupFlashPicElement struct {
GroupImageElement
}
@ -122,6 +129,10 @@ type GroupShowPicElement struct {
EffectId int32
}
type FriendFlashImgElement struct {
ImageElement
}
type FriendFlashPicElement struct {
FriendImageElement
}
@ -238,6 +249,14 @@ func (e *ImageElement) Type() ElementType {
return Image
}
func (e *GroupFlashImgElement) Type() ElementType {
return Image
}
func (e *FriendFlashImgElement) Type() ElementType {
return Image
}
func (e *FaceElement) Type() ElementType {
return Face
}

View File

@ -2,16 +2,17 @@ package message
import (
"crypto/md5"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/golang/protobuf/proto"
"github.com/tidwall/gjson"
"math"
"reflect"
"regexp"
"strconv"
"strings"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/golang/protobuf/proto"
"github.com/tidwall/gjson"
)
type (
@ -132,6 +133,9 @@ func (msg *PrivateMessage) ToString() (res string) {
res += e.Content
case *ImageElement:
res += "[Image:" + e.Filename + "]"
case *FriendFlashImgElement:
// NOTE: ignore other components
return "[Image (flash):" + e.Filename + "]"
case *FaceElement:
res += "[" + e.Name + "]"
case *AtElement:
@ -168,6 +172,9 @@ func (msg *GroupMessage) ToString() (res string) {
res += "[" + e.Name + "]"
case *GroupImageElement:
res += "[Image: " + e.ImageId + "]"
case *GroupFlashImgElement:
// NOTE: ignore other components
return "[Image (flash):" + e.Filename + "]"
case *AtElement:
res += e.Display
case *RedBagElement:
@ -488,20 +495,26 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
flash := &msg.MsgElemInfoServtype3{}
_ = proto.Unmarshal(elem.CommonElem.PbElem, flash)
if flash.FlashTroopPic != nil {
res = append(res, &ImageElement{
Filename: flash.FlashTroopPic.FilePath,
Size: flash.FlashTroopPic.Size,
Width: flash.FlashTroopPic.Width,
Height: flash.FlashTroopPic.Height,
Md5: flash.FlashTroopPic.Md5,
res = append(res, &GroupFlashImgElement{
ImageElement{
Filename: flash.FlashTroopPic.FilePath,
Size: flash.FlashTroopPic.Size,
Width: flash.FlashTroopPic.Width,
Height: flash.FlashTroopPic.Height,
Md5: flash.FlashTroopPic.Md5,
},
})
return res
}
if flash.FlashC2CPic != nil {
res = append(res, &ImageElement{
Filename: flash.FlashC2CPic.FilePath,
Size: flash.FlashC2CPic.FileLen,
Md5: flash.FlashC2CPic.PicMd5,
res = append(res, &GroupFlashImgElement{
ImageElement{
Filename: flash.FlashC2CPic.FilePath,
Size: flash.FlashC2CPic.FileLen,
Md5: flash.FlashC2CPic.PicMd5,
},
})
return res
}
}
}
@ -560,6 +573,12 @@ func ToReadableString(m []IMessageElement) (r string) {
r += "/" + e.Name
case *GroupImageElement:
r += "[图片]"
// NOTE: flash pic is singular
// To be clarified
// case *GroupFlashImgElement:
// return "[闪照]"
// case *FriendFlashImgElement:
// return "[闪照]"
case *AtElement:
r += e.Display
}