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

fix typo.

This commit is contained in:
Mrs4s 2020-07-15 18:38:58 +08:00
parent a6bef48fe2
commit ef3d1cab23
6 changed files with 31 additions and 20 deletions

View File

@ -2,7 +2,7 @@
qq-android协议的golang实现 移植于Mirai qq-android协议的golang实现 移植于Mirai
# 警告 # 警告
本项目目前还处于玩具阶段,强烈不推荐使用. 本项目目前还处于功能填充阶段将来API和项目结构可能会有调整目前不推荐使用。
# 已完成功能/开发计划 # 已完成功能/开发计划
#### 登录 #### 登录
@ -14,6 +14,7 @@ qq-android协议的golang实现 移植于Mirai
#### 消息类型 #### 消息类型
- [x] 文本 - [x] 文本
- [x] 图片 - [x] 图片
- [x] 表情
- [x] At - [x] At
- [x] 回复 - [x] 回复
- [ ] 长消息 - [ ] 长消息

View File

@ -3,6 +3,7 @@ package client
import ( import (
"crypto/md5" "crypto/md5"
"errors" "errors"
"fmt"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client/pb" "github.com/Mrs4s/MiraiGo/client/pb"
"github.com/Mrs4s/MiraiGo/message" "github.com/Mrs4s/MiraiGo/message"
@ -187,7 +188,7 @@ func (c *QQClient) GetFriendList() (*FriendListResponse, error) {
return r, nil return r, nil
} }
func (c *QQClient) SendGroupMessage(groupUin int64, m *message.SendingMessage) int32 { func (c *QQClient) SendGroupMessage(groupCode int64, m *message.SendingMessage) int32 {
eid := utils.RandomString(6) eid := utils.RandomString(6)
mr := int32(rand.Uint32()) mr := int32(rand.Uint32())
ch := make(chan int32) ch := make(chan int32)
@ -197,7 +198,7 @@ func (c *QQClient) SendGroupMessage(groupUin int64, m *message.SendingMessage) i
c.onGroupMessageReceipt(eid) c.onGroupMessageReceipt(eid)
} }
}) })
_, pkt := c.buildGroupSendingPacket(utils.ToGroupCode(groupUin), mr, m) _, pkt := c.buildGroupSendingPacket(groupCode, mr, m)
_ = c.send(pkt) _ = c.send(pkt)
var mid int32 var mid int32
select { select {
@ -321,7 +322,7 @@ func (c *QQClient) FindFriend(uin int64) *FriendInfo {
return nil return nil
} }
func (c *QQClient) FindGroup(uin int64) *GroupInfo { func (c *QQClient) FindGroupByUin(uin int64) *GroupInfo {
for _, g := range c.GroupList { for _, g := range c.GroupList {
f := g f := g
if f.Uin == uin { if f.Uin == uin {
@ -331,6 +332,16 @@ func (c *QQClient) FindGroup(uin int64) *GroupInfo {
return nil return nil
} }
func (c *QQClient) FindGroup(code int64) *GroupInfo {
for _, g := range c.GroupList {
f := g
if f.Code == code {
return f
}
}
return nil
}
func (g *GroupInfo) FindMember(uin int64) *GroupMemberInfo { func (g *GroupInfo) FindMember(uin int64) *GroupMemberInfo {
for _, m := range g.Members { for _, m := range g.Members {
f := m f := m
@ -451,7 +462,7 @@ func (c *QQClient) loop() {
continue continue
} }
} }
//fmt.Println(pkt.CommandName) fmt.Println(pkt.CommandName)
go func() { go func() {
decoder, ok := c.decoders[pkt.CommandName] decoder, ok := c.decoders[pkt.CommandName]
if !ok { if !ok {

View File

@ -155,10 +155,10 @@ func decodeMessageSvcPacket(c *QQClient, _ uint16, payload []byte) (interface{},
switch message.Head.MsgType { switch message.Head.MsgType {
case 33: case 33:
groupJoinLock.Lock() groupJoinLock.Lock()
group := c.FindGroup(message.Head.FromUin) group := c.FindGroupByUin(message.Head.FromUin)
if message.Head.AuthUin == c.Uin { if message.Head.AuthUin == c.Uin {
if group == nil && c.ReloadGroupList() == nil { if group == nil && c.ReloadGroupList() == nil {
c.dispatchJoinGroupEvent(c.FindGroup(message.Head.FromUin)) c.dispatchJoinGroupEvent(c.FindGroupByUin(message.Head.FromUin))
} }
} else { } else {
if group != nil && group.FindMember(message.Head.AuthUin) == nil { if group != nil && group.FindMember(message.Head.AuthUin) == nil {
@ -366,7 +366,7 @@ func decodeOnlinePushReqPacket(c *QQClient, seq uint16, payload []byte) (interfa
target := int64(uint32(r.ReadInt32())) target := int64(uint32(r.ReadInt32()))
t := r.ReadInt32() t := r.ReadInt32()
c.dispatchGroupMuteEvent(&GroupMuteEvent{ c.dispatchGroupMuteEvent(&GroupMuteEvent{
GroupUin: groupId, GroupCode: groupId,
OperatorUin: operator, OperatorUin: operator,
TargetUin: target, TargetUin: target,
Time: t, Time: t,
@ -380,7 +380,7 @@ func decodeOnlinePushReqPacket(c *QQClient, seq uint16, payload []byte) (interfa
} }
for _, rm := range b.OptMsgRecall.RecalledMsgList { for _, rm := range b.OptMsgRecall.RecalledMsgList {
c.dispatchGroupMessageRecalledEvent(&GroupMessageRecalledEvent{ c.dispatchGroupMessageRecalledEvent(&GroupMessageRecalledEvent{
GroupUin: groupId, GroupCode: groupId,
OperatorUin: b.OptMsgRecall.Uin, OperatorUin: b.OptMsgRecall.Uin,
AuthorUin: rm.AuthorUin, AuthorUin: rm.AuthorUin,
MessageId: rm.Seq, MessageId: rm.Seq,
@ -400,7 +400,7 @@ func decodeOnlinePushReqPacket(c *QQClient, seq uint16, payload []byte) (interfa
return nil, err return nil, err
} }
groupLeaveLock.Lock() groupLeaveLock.Lock()
if g := c.FindGroup(d4.Uin); g != nil { if g := c.FindGroupByUin(d4.Uin); g != nil {
if err := c.ReloadGroupList(); err != nil { if err := c.ReloadGroupList(); err != nil {
groupLeaveLock.Unlock() groupLeaveLock.Unlock()
return nil, err return nil, err
@ -428,7 +428,7 @@ func decodeOnlinePushTransPacket(c *QQClient, _ uint16, payload []byte) (interfa
target := int64(uint32(data.ReadInt32())) target := int64(uint32(data.ReadInt32()))
typ := int32(data.ReadByte()) typ := int32(data.ReadByte())
operator := int64(uint32(data.ReadInt32())) operator := int64(uint32(data.ReadInt32()))
if g := c.FindGroup(info.FromUin); g != nil { if g := c.FindGroupByUin(info.FromUin); g != nil {
switch typ { switch typ {
case 0x03: case 0x03:
groupLeaveLock.Lock() groupLeaveLock.Lock()
@ -469,7 +469,7 @@ func decodeOnlinePushTransPacket(c *QQClient, _ uint16, payload []byte) (interfa
if var4 != 0 && var4 != 1 { if var4 != 0 && var4 != 1 {
var5 = int64(uint32(data.ReadInt32())) var5 = int64(uint32(data.ReadInt32()))
} }
if g := c.FindGroup(info.FromUin); g != nil { if g := c.FindGroupByUin(info.FromUin); g != nil {
if var5 == 0 && data.Len() == 1 { if var5 == 0 && data.Len() == 1 {
newPermission := func() MemberPermission { newPermission := func() MemberPermission {
if data.ReadByte() == 1 { if data.ReadByte() == 1 {

View File

@ -67,14 +67,14 @@ type (
} }
GroupMuteEvent struct { GroupMuteEvent struct {
GroupUin int64 GroupCode int64
OperatorUin int64 OperatorUin int64
TargetUin int64 TargetUin int64
Time int32 Time int32
} }
GroupMessageRecalledEvent struct { GroupMessageRecalledEvent struct {
GroupUin int64 GroupCode int64
OperatorUin int64 OperatorUin int64
AuthorUin int64 AuthorUin int64
MessageId int32 MessageId int32

View File

@ -6,7 +6,6 @@ import (
devinfo "github.com/Mrs4s/MiraiGo/client/pb" devinfo "github.com/Mrs4s/MiraiGo/client/pb"
"github.com/Mrs4s/MiraiGo/client/pb/msg" "github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/message" "github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"math/rand" "math/rand"
) )
@ -98,7 +97,7 @@ func (info *DeviceInfo) GenNewTgtgtKey() {
} }
func (info *DeviceInfo) GenDeviceInfoData() []byte { func (info *DeviceInfo) GenDeviceInfoData() []byte {
msg := &devinfo.DeviceInfo{ m := &devinfo.DeviceInfo{
Bootloader: string(info.Bootloader), Bootloader: string(info.Bootloader),
ProcVersion: string(info.ProcVersion), ProcVersion: string(info.ProcVersion),
Codename: string(info.Version.CodeName), Codename: string(info.Version.CodeName),
@ -109,7 +108,7 @@ func (info *DeviceInfo) GenDeviceInfoData() []byte {
BaseBand: string(info.BaseBand), BaseBand: string(info.BaseBand),
InnerVersion: string(info.Version.Incremental), InnerVersion: string(info.Version.Incremental),
} }
data, err := proto.Marshal(msg) data, err := proto.Marshal(m)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -132,7 +131,7 @@ func (c *QQClient) parsePrivateMessage(msg *msg.Message) *message.PrivateMessage
} }
func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage { func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
group := c.FindGroup(utils.ToGroupUin(m.Head.GroupInfo.GroupCode)) group := c.FindGroup(m.Head.GroupInfo.GroupCode)
if group == nil { if group == nil {
return nil return nil
} }
@ -163,7 +162,7 @@ func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
} }
g := &message.GroupMessage{ g := &message.GroupMessage{
Id: m.Head.MsgSeq, Id: m.Head.MsgSeq,
GroupUin: group.Uin, GroupCode: group.Code,
GroupName: string(m.Head.GroupInfo.GroupName), GroupName: string(m.Head.GroupInfo.GroupName),
Sender: sender, Sender: sender,
Elements: parseMessageElems(m.Body.RichText.Elems), Elements: parseMessageElems(m.Body.RichText.Elems),

View File

@ -14,7 +14,7 @@ type PrivateMessage struct {
type GroupMessage struct { type GroupMessage struct {
Id int32 Id int32
GroupUin int64 GroupCode int64
GroupName string GroupName string
Sender *Sender Sender *Sender
Elements []IMessageElement Elements []IMessageElement