Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Commit

Permalink
feat: add friendMsg Parse
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoo committed Oct 24, 2023
1 parent eddaeac commit b4d790d
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 117 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/dop251/goja v0.0.0-20210427212725-462d53687b0d
github.com/goinggo/mapstructure v0.0.0-20140717182941-194205d9b4a9
github.com/gorilla/websocket v1.4.2
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mcoo/requests v0.0.2
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.2 // indirect
Expand Down
60 changes: 46 additions & 14 deletions v2/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package events

import (
"context"
"encoding/json"
"strings"
)

//go:generate easyjson events.go

type EventName string

const (
Expand Down Expand Up @@ -48,11 +49,20 @@ type IEvent interface {
GetRawBytes() []byte
GetEventName() EventName
ParseGroupMsg() IGroupMsg
ParseFriendMsg() IFriendMsg
ParseLoginSuccessEvent() ILoginSuccess
ParseNetworkChangeEvent() INetworkChange
PraseGroupJoinEvent() IGroupJoinEvent
ExcludeBot() IEvent
}
type IFriendMsg interface {
ICommonMsg
GetFriendUin() int64
GetFriendUid() string
GetSenderUin() int64
ParseTextMsg() ITextMsg
ParsePicMsg() IPicMsg
}
type IGroupMsg interface {
ICommonMsg
ExcludeAtInfo() IGroupMsg
Expand All @@ -63,15 +73,18 @@ type IGroupMsg interface {
GetSenderNick() string
GetSenderUin() int64
ParseTextMsg() ITextMsg
ParsePicMsg() IPicMsg
ContainedPic() bool
ContainedAt() bool
GetMsgSeq() int64
GetMsgRandom() int64
IsFromBot() bool
}
type ITextMsg interface {
GetTextContent() string
}
type IPicMsg interface {
GetPics() []Image
GetTextContent() string
}
type ILoginSuccess interface {
GetLoginSuccessBot() (nick string, uin int64)
}
Expand All @@ -88,6 +101,8 @@ type ICommonMsg interface {
GetMsgUid() int64
GetMsgType() MsgType
GetMsgTime() int64
GetMsgSeq() int64
GetMsgRandom() int64
}

func New(data []byte) (IEvent, error) {
Expand All @@ -97,11 +112,9 @@ func New(data []byte) (IEvent, error) {
return nil, err
}
event.rawEvent = data
return event, json.Unmarshal(data, event)
return event, err
}

//go:generate easyjson events.go

type GroupInfo struct {
GroupCard string `json:"GroupCard"`
GroupCode int `json:"GroupCode"`
Expand All @@ -115,6 +128,12 @@ type UserInfo struct {
Nick string `json:"Nick"`
Uin int64 `json:"Uin"`
}
type Image struct {
FileId int64 `json:"FileId"`
FileMd5 string `json:"FileMd5"`
FileSize int `json:"FileSize"`
Url string `json:"Url"`
}

//easyjson:json
type EventStruct struct {
Expand All @@ -126,9 +145,11 @@ type EventStruct struct {
Content *string `json:"Content,omitempty"`
MsgHead *struct {
FromUin int64 `json:"FromUin"`
FromUid string `json:"FromUid"`
ToUin int64 `json:"ToUin"`
FromType int `json:"FromType"`
SenderUin int64 `json:"SenderUin"`
SenderUid string `json:"SenderUid"`
SenderNick string `json:"SenderNick"`
MsgType int `json:"MsgType"`
C2CCmd int `json:"C2cCmd"`
Expand All @@ -140,14 +161,9 @@ type EventStruct struct {
C2CTempMessageHead interface{} `json:"C2CTempMessageHead"`
} `json:"MsgHead,omitempty"`
MsgBody *struct {
SubMsgType int `json:"SubMsgType"`
Content string `json:"Content"`
Images []struct {
FileId int64 `json:"FileId"`
FileMd5 string `json:"FileMd5"`
FileSize int `json:"FileSize"`
Url string `json:"Url"`
} `json:"Images"`
SubMsgType int `json:"SubMsgType"`
Content string `json:"Content"`
Images []Image `json:"Images"`
AtUinLists []UserInfo `json:"AtUinLists"`
Video interface{} `json:"Video"`
Voice interface{} `json:"Voice"`
Expand Down Expand Up @@ -260,12 +276,21 @@ func (e *EventStruct) ParseTextMsg() ITextMsg {
func (e *EventStruct) ParseGroupMsg() IGroupMsg {
return e
}
func (e *EventStruct) ParseFriendMsg() IFriendMsg {
return e
}
func (e *EventStruct) GetMsgUid() int64 {
return e.CurrentPacket.EventData.MsgHead.MsgUid
}
func (e *EventStruct) GetGroupUin() int64 {
return e.CurrentPacket.EventData.MsgHead.FromUin
}
func (e *EventStruct) GetFriendUin() int64 {
return e.CurrentPacket.EventData.MsgHead.FromUin
}
func (e *EventStruct) GetFriendUid() string {
return e.CurrentPacket.EventData.MsgHead.FromUid
}
func (e *EventStruct) GetGroupInfo() GroupInfo {
return e.CurrentPacket.EventData.MsgHead.GroupInfo
}
Expand All @@ -283,3 +308,10 @@ func (e *EventStruct) GetLoginSuccessBot() (nick string, uin int64) {
uin = *e.CurrentPacket.EventData.Uin
return
}

func (e *EventStruct) ParsePicMsg() IPicMsg {
return e
}
func (e *EventStruct) GetPics() []Image {
return e.CurrentPacket.EventData.MsgBody.Images
}
Loading

0 comments on commit b4d790d

Please sign in to comment.