Skip to content

Commit

Permalink
supported more group operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Jul 20, 2020
1 parent 0a8fa22 commit a0cac46
Show file tree
Hide file tree
Showing 6 changed files with 1,826 additions and 9 deletions.
68 changes: 67 additions & 1 deletion client/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/Mrs4s/MiraiGo/client/pb"
"github.com/Mrs4s/MiraiGo/client/pb/cmd0x352"
"github.com/Mrs4s/MiraiGo/client/pb/msg"
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
"github.com/Mrs4s/MiraiGo/client/pb/structmsg"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/protocol/crypto"
Expand Down Expand Up @@ -701,10 +702,75 @@ func (c *QQClient) buildEditGroupTagPacket(groupCode, memberUin int64, newTag st
Context: map[string]string{},
Status: map[string]string{},
}
packet := packets.BuildUniPacket(c.Uin, seq, "friendlist.ModifyGroupCardReq", 1, c.OutGoingPacketSessionId, []byte{}, c.sigInfo.d2Key, pkt.ToBytes())
packet := packets.BuildUniPacket(c.Uin, seq, "friendlist.ModifyGroupCardReq", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, pkt.ToBytes())
return seq, packet
}

// OidbSvc.0x8fc_2
func (c *QQClient) buildEditSpecialTitlePacket(groupCode, memberUin int64, newTitle string) (uint16, []byte) {
seq := c.nextSeq()
body := &oidb.D8FCReqBody{
GroupCode: groupCode,
MemLevelInfo: []*oidb.D8FCMemberInfo{
{
Uin: memberUin,
UinName: []byte(newTitle),
SpecialTitle: []byte(newTitle),
SpecialTitleExpireTime: -1,
},
},
}
b, _ := proto.Marshal(body)
req := &oidb.OIDBSSOPkg{
Command: 2300,
ServiceType: 2,
Bodybuffer: b,
}
payload, _ := proto.Marshal(req)
packet := packets.BuildUniPacket(c.Uin, seq, "OidbSvc.0x8fc_2", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
return seq, packet
}

// OidbSvc.0x89a_0
func (c *QQClient) buildGroupOperationPacket(body *oidb.D89AReqBody) (uint16, []byte) {
seq := c.nextSeq()
b, _ := proto.Marshal(body)
req := &oidb.OIDBSSOPkg{
Command: 2202,
Bodybuffer: b,
}
payload, _ := proto.Marshal(req)
packet := packets.BuildUniPacket(c.Uin, seq, "OidbSvc.0x89a_0", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
return seq, packet
}

// OidbSvc.0x89a_0
func (c *QQClient) buildGroupNameUpdatePacket(groupCode int64, newName string) (uint16, []byte) {
body := &oidb.D89AReqBody{
GroupCode: groupCode,
StGroupInfo: &oidb.D89AGroupinfo{
IngGroupName: []byte(newName),
},
}
return c.buildGroupOperationPacket(body)
}

// OidbSvc.0x89a_0
func (c *QQClient) buildGroupMuteAllPacket(groupCode int64, mute bool) (uint16, []byte) {
body := &oidb.D89AReqBody{
GroupCode: groupCode,
StGroupInfo: &oidb.D89AGroupinfo{
ShutupTime: func() int32 {
if mute {
return 1
}
return 0
}(),
},
}
return c.buildGroupOperationPacket(body)
}

/*
func (c *QQClient) buildMultiMsgDownRequestPacket() (uint16, []byte){
seq := c.nextSeq()
Expand Down
18 changes: 17 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ func (g *GroupInfo) SelfPermission() MemberPermission {
return g.FindMember(g.bot.Uin).Permission
}

func (g *GroupInfo) AdministratorOrOwner() bool {
return g.SelfPermission() == Administrator || g.SelfPermission() == Owner
}

func (g *GroupInfo) FindMember(uin int64) *GroupMemberInfo {
for _, m := range g.Members {
f := m
Expand All @@ -445,10 +449,22 @@ func (g *GroupInfo) FindMember(uin int64) *GroupMemberInfo {
return nil
}

func (c *QQClient) EditMemberCard(groupCode, memberUin int64, card string) {
func (c *QQClient) editMemberCard(groupCode, memberUin int64, card string) {
_, _ = c.sendAndWait(c.buildEditGroupTagPacket(groupCode, memberUin, card))
}

func (c *QQClient) editMemberSpecialTitle(groupCode, memberUin int64, title string) {
_, _ = c.sendAndWait(c.buildEditSpecialTitlePacket(groupCode, memberUin, title))
}

func (c *QQClient) updateGroupName(groupCode int64, newName string) {
_, _ = c.sendAndWait(c.buildGroupNameUpdatePacket(groupCode, newName))
}

func (c *QQClient) groupMuteAll(groupCode int64, mute bool) {
_, _ = c.sendAndWait(c.buildGroupMuteAllPacket(groupCode, mute))
}

func (g *GroupInfo) removeMember(uin int64) {
if g.memLock == nil {
g.memLock = new(sync.Mutex)
Expand Down
25 changes: 23 additions & 2 deletions client/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"errors"
"strings"
"sync"
)

Expand Down Expand Up @@ -174,6 +175,19 @@ const (
Member
)

func (g *GroupInfo) UpdateName(newName string) {
if g.AdministratorOrOwner() && strings.Count(newName, "") <= 20 {
g.bot.updateGroupName(g.Code, newName)
g.Name = newName
}
}

func (g *GroupInfo) MuteAll(mute bool) {
if g.AdministratorOrOwner() {
g.bot.groupMuteAll(g.Code, mute)
}
}

func (m *GroupMemberInfo) DisplayName() string {
if m.CardName == "" {
return m.Nickname
Expand All @@ -182,12 +196,19 @@ func (m *GroupMemberInfo) DisplayName() string {
}

func (m *GroupMemberInfo) EditCard(card string) {
if m.Manageable() {
m.Group.bot.EditMemberCard(m.Group.Code, m.Uin, card)
if m.Manageable() && strings.Count(card, "") <= 20 {
m.Group.bot.editMemberCard(m.Group.Code, m.Uin, card)
m.CardName = card
}
}

func (m *GroupMemberInfo) EditSpecialTitle(title string) {
if m.Group.SelfPermission() == Owner && strings.Count(title, "") <= 6 {
m.Group.bot.editMemberSpecialTitle(m.Group.Code, m.Uin, title)
m.SpecialTitle = title
}
}

func (m *GroupMemberInfo) Manageable() bool {
if m.Uin == m.Group.bot.Uin {
return true
Expand Down
Loading

0 comments on commit a0cac46

Please sign in to comment.