Skip to content

Commit

Permalink
refactor: 统一函数和文件名称
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 27, 2024
1 parent f461272 commit 96210f1
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 99 deletions.
24 changes: 12 additions & 12 deletions client/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,36 +212,36 @@ func (c *QQClient) preProcessGroupMessage(groupUin uint32, elements []message2.I
if elem.MsgInfo != nil {
continue
}
_, err := c.ImageUploadGroup(groupUin, elem)
_, err := c.UploadGroupImage(groupUin, elem)
if err != nil {
c.errorln(err)
}
if elem.MsgInfo == nil {
c.errorln("ImageUploadGroup failed")
c.errorln("UploadGroupImage failed")
continue
}
case *message2.VoiceElement:
if elem.MsgInfo != nil {
continue
}
_, err := c.RecordUploadGroup(groupUin, elem)
_, err := c.UploadGroupRecord(groupUin, elem)
if err != nil {
c.errorln(err)
}
if elem.MsgInfo == nil {
c.errorln("RecordUploadGroup failed")
c.errorln("UploadGroupRecord failed")
continue
}
case *message2.ShortVideoElement:
if elem.MsgInfo != nil {
continue
}
_, err := c.VideoUploadGroup(groupUin, elem)
_, err := c.UploadGroupVideo(groupUin, elem)
if err != nil {
c.errorln(err)
}
if elem.MsgInfo == nil {
c.errorln("VideoUploadGroup failed")
c.errorln("UploadGroupVideo failed")
continue
}
case *message2.ForwardMessage:
Expand Down Expand Up @@ -270,41 +270,41 @@ func (c *QQClient) preProcessPrivateMessage(targetUin uint32, elements []message
continue
}
targetUID := c.GetUID(targetUin)
_, err := c.ImageUploadPrivate(targetUID, elem)
_, err := c.UploadPrivateImage(targetUID, elem)
if err != nil {
c.errorln(err)
continue
}
if elem.MsgInfo == nil {
c.errorln("ImageUploadPrivate failed")
c.errorln("UploadPrivateImage failed")
continue
}
case *message2.VoiceElement:
if elem.MsgInfo != nil {
continue
}
targetUID := c.GetUID(targetUin)
_, err := c.RecordUploadPrivate(targetUID, elem)
_, err := c.UploadPrivateRecord(targetUID, elem)
if err != nil {
c.errorln(err)
continue
}
if elem.MsgInfo == nil {
c.errorln("RecordUploadPrivate failed")
c.errorln("UploadPrivateRecord failed")
continue
}
case *message2.ShortVideoElement:
if elem.MsgInfo != nil {
continue
}
targetUID := c.GetUID(targetUin)
_, err := c.VideoUploadPrivate(targetUID, elem)
_, err := c.UploadPrivateVideo(targetUID, elem)
if err != nil {
c.errorln(err)
continue
}
if elem.MsgInfo == nil {
c.errorln("VideoUploadPrivate failed")
c.errorln("UploadPrivateVideo failed")
continue
}
case *message2.ForwardMessage:
Expand Down
96 changes: 48 additions & 48 deletions client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,90 +123,90 @@ func (c *QQClient) FetchGroupMembers(groupUin uint32, token string) ([]*entity.G
return members, newToken, nil
}

// GroupRemark 设置群聊备注
func (c *QQClient) GroupRemark(groupUin uint32, remark string) error {
pkt, err := oidb2.BuildGroupRemarkReq(groupUin, remark)
// SetGroupRemark 设置群聊备注
func (c *QQClient) SetGroupRemark(groupUin uint32, remark string) error {
pkt, err := oidb2.BuildSetGroupRemarkReq(groupUin, remark)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
return oidb2.ParseGroupRemarkResp(resp)
return oidb2.ParseSetGroupRemarkResp(resp)
}

// GroupRename 设置群聊名称
func (c *QQClient) GroupRename(groupUin uint32, name string) error {
pkt, err := oidb2.BuildGroupRenameReq(groupUin, name)
// SetGroupName 设置群聊名称
func (c *QQClient) SetGroupName(groupUin uint32, name string) error {
pkt, err := oidb2.BuildSetGroupNameReq(groupUin, name)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
return oidb2.ParseGroupRenameResp(resp)
return oidb2.ParseSetGroupNameResp(resp)
}

// GroupMuteGlobal 群全员禁言
func (c *QQClient) GroupMuteGlobal(groupUin uint32, isMute bool) error {
pkt, err := oidb2.BuildGroupMuteGlobalReq(groupUin, isMute)
// SetGroupGlobalMute 群全员禁言
func (c *QQClient) SetGroupGlobalMute(groupUin uint32, isMute bool) error {
pkt, err := oidb2.BuildSetGroupGlobalMuteReq(groupUin, isMute)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
return oidb2.ParseGroupMuteGlobalResp(resp)
return oidb2.ParseSetGroupGlobalMuteResp(resp)
}

// GroupMuteMember 禁言群成员
func (c *QQClient) GroupMuteMember(groupUin, uin, duration uint32) error {
// SetGroupMemberMute 禁言群成员
func (c *QQClient) SetGroupMemberMute(groupUin, uin, duration uint32) error {
uid := c.GetUID(uin, groupUin)
if uid == "" {
return errors.New("uid not found")
}
pkt, err := oidb2.BuildGroupMuteMemberReq(groupUin, duration, uid)
pkt, err := oidb2.BuildSetGroupMemberMuteReq(groupUin, duration, uid)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
return oidb2.ParseGroupMuteMemberResp(resp)
return oidb2.ParseSetGroupMemberMuteResp(resp)
}

// GroupLeave 退出群聊
func (c *QQClient) GroupLeave(groupUin uint32) error {
pkt, err := oidb2.BuildGroupLeaveReq(groupUin)
// SetGroupLeave 退出群聊
func (c *QQClient) SetGroupLeave(groupUin uint32) error {
pkt, err := oidb2.BuildSetGroupLeaveReq(groupUin)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
return oidb2.ParseGroupLeaveResp(resp)
return oidb2.ParseSetGroupLeaveResp(resp)
}

// GroupSetAdmin 设置群管理员
func (c *QQClient) GroupSetAdmin(groupUin, uin uint32, isAdmin bool) error {
// SetGroupAdmin 设置群管理员
func (c *QQClient) SetGroupAdmin(groupUin, uin uint32, isAdmin bool) error {
uid := c.GetUID(uin, groupUin)
if uid == "" {
return errors.New("uid not found")
}
pkt, err := oidb2.BuildGroupSetAdminReq(groupUin, uid, isAdmin)
pkt, err := oidb2.BuildSetGroupAdminReq(groupUin, uid, isAdmin)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
err = oidb2.ParseGroupSetAdminResp(resp)
err = oidb2.ParseSetGroupAdminResp(resp)
if err != nil {
return err
}
Expand All @@ -217,21 +217,21 @@ func (c *QQClient) GroupSetAdmin(groupUin, uin uint32, isAdmin bool) error {
return nil
}

// GroupRenameMember 设置群成员昵称
func (c *QQClient) GroupRenameMember(groupUin, uin uint32, name string) error {
// SetGroupMemberName 设置群成员昵称
func (c *QQClient) SetGroupMemberName(groupUin, uin uint32, name string) error {
uid := c.GetUID(uin, groupUin)
if uid == "" {
return errors.New("uid not found")
}
pkt, err := oidb2.BuildGroupRenameMemberReq(groupUin, uid, name)
pkt, err := oidb2.BuildSetGroupMemberNameReq(groupUin, uid, name)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
err = oidb2.ParseGroupRenameMemberResp(resp)
err = oidb2.ParseSetGroupMemberNameResp(resp)
if err != nil {
return err
}
Expand All @@ -242,51 +242,51 @@ func (c *QQClient) GroupRenameMember(groupUin, uin uint32, name string) error {
return nil
}

// GroupKickMember 踢出群成员,可选是否拒绝加群请求
func (c *QQClient) GroupKickMember(groupUin, uin uint32, rejectAddRequest bool) error {
// KickGroupMember 踢出群成员,可选是否拒绝加群请求
func (c *QQClient) KickGroupMember(groupUin, uin uint32, rejectAddRequest bool) error {
uid := c.GetUID(uin, groupUin)
if uid == "" {
return errors.New("uid not found")
}
pkt, err := oidb2.BuildGroupKickMemberReq(groupUin, uid, rejectAddRequest)
pkt, err := oidb2.BuildKickGroupMemberReq(groupUin, uid, rejectAddRequest)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
return oidb2.ParseGroupKickMemberResp(resp)
return oidb2.ParseKickGroupMemberResp(resp)
}

// GroupSetSpecialTitle 设置群成员专属头衔
func (c *QQClient) GroupSetSpecialTitle(groupUin, uin uint32, title string) error {
// SetGroupMemberSpecialTitle 设置群成员专属头衔
func (c *QQClient) SetGroupMemberSpecialTitle(groupUin, uin uint32, title string) error {
uid := c.GetUID(uin, groupUin)
if uid == "" {
return errors.New("uid not found")
}
pkt, err := oidb2.BuildGroupSetSpecialTitleReq(groupUin, uid, title)
pkt, err := oidb2.BuildSetGroupMemberSpecialTitleReq(groupUin, uid, title)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
return oidb2.ParseGroupSetSpecialTitleResp(resp)
return oidb2.ParseSetGroupMemberSpecialTitleResp(resp)
}

// GroupSetReaction 设置群消息表态
func (c *QQClient) GroupSetReaction(groupUin, sequence uint32, code string, isAdd bool) error {
pkt, err := oidb2.BuildGroupSetReactionReq(groupUin, sequence, code, isAdd)
// SetGroupReaction 设置群消息表态
func (c *QQClient) SetGroupReaction(groupUin, sequence uint32, code string, isAdd bool) error {
pkt, err := oidb2.BuildSetGroupReactionReq(groupUin, sequence, code, isAdd)
if err != nil {
return err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return err
}
return oidb2.ParseGroupSetReactionResp(resp)
return oidb2.ParseSetGroupReactionResp(resp)
}

// GroupPoke 戳一戳群友
Expand Down Expand Up @@ -671,13 +671,13 @@ func (c *QQClient) FetchCookies(domains []string) ([]string, error) {
return oidb2.ParseFetchCookieResp(resp)
}

// UploadPrivateFile 上传私聊文件
func (c *QQClient) UploadPrivateFile(targetUin uint32, localFilePath, filename string) error {
// SendPrivateFile 发送私聊文件
func (c *QQClient) SendPrivateFile(targetUin uint32, localFilePath, filename string) error {
fileElement, err := message2.NewLocalFile(localFilePath, filename)
if err != nil {
return err
}
uploadedFileElement, err := c.FileUploadPrivate(c.GetUID(targetUin), fileElement)
uploadedFileElement, err := c.UploadPrivateFile(c.GetUID(targetUin), fileElement)
if err != nil {
return err
}
Expand All @@ -696,13 +696,13 @@ func (c *QQClient) UploadPrivateFile(targetUin uint32, localFilePath, filename s
return nil
}

// UploadGroupFile 上传群文件
func (c *QQClient) UploadGroupFile(groupUin uint32, localFilePath, filename, targetDirectory string) error {
// SendGroupFile 发送群文件
func (c *QQClient) SendGroupFile(groupUin uint32, localFilePath, filename, targetDirectory string) error {
fileElement, err := message2.NewLocalFile(localFilePath, filename)
if err != nil {
return err
}
if _, err = c.FileUploadGroup(groupUin, fileElement, targetDirectory); err != nil {
if _, err = c.UploadGroupFile(groupUin, fileElement, targetDirectory); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -1410,13 +1410,13 @@ func (c *QQClient) CheckURLSafely(url string) (oidb2.URLSecurityLevel, error) {
// GetAtAllRemain 获取剩余@全员次数
// ref https://github.com/Mrs4s/MiraiGo/blob/54bdd873e3fed9fe1c944918924674dacec5ac76/client/group_msg.go#L68
func (c *QQClient) GetAtAllRemain(uin, groupUin uint32) (*oidb2.AtAllRemainInfo, error) {
pkt, err := oidb2.BuildAtAllRemainRequest(uin, groupUin)
pkt, err := oidb2.BuildGetAtAllRemainRequest(uin, groupUin)
if err != nil {
return nil, err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return nil, err
}
return oidb2.ParseAtAllRemainResponse(resp)
return oidb2.ParseGetAtAllRemainResponse(resp)
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package oidb
import "github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb"

// ref https://github.com/Mrs4s/MiraiGo/blob/54bdd873e3fed9fe1c944918924674dacec5ac76/client/group_msg.go#L213
func BuildAtAllRemainRequest(uin, gin uint32) (*Packet, error) {

func BuildGetAtAllRemainRequest(uin, gin uint32) (*Packet, error) {
body := &oidb.OidbSvcTrpcTcp0X8A7_0_ReqBody{
SubCmd: 1,
LimitIntervalTypeForUin: 2,
Expand All @@ -20,8 +21,7 @@ type AtAllRemainInfo struct {
CountForUin uint32 // 当前QQ剩余次数
}

// ref https://github.com/Mrs4s/MiraiGo/blob/54bdd873e3fed9fe1c944918924674dacec5ac76/client/group_msg.go#L326
func ParseAtAllRemainResponse(data []byte) (*AtAllRemainInfo, error) {
func ParseGetAtAllRemainResponse(data []byte) (*AtAllRemainInfo, error) {
var rsp oidb.OidbSvcTrpcTcp0X8A7_0_RspBody
_, err := ParseOidbPacket(data, &rsp)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb"
)

func BuildGroupKickMemberReq(groupUin uint32, uid string, rejectAddRequest bool) (*Packet, error) {
func BuildKickGroupMemberReq(groupUin uint32, uid string, rejectAddRequest bool) (*Packet, error) {
body := &oidb.OidbSvcTrpcTcp0X8A0_1{
GroupUin: groupUin,
TargetUid: uid,
Expand All @@ -14,6 +14,6 @@ func BuildGroupKickMemberReq(groupUin uint32, uid string, rejectAddRequest bool)
return BuildOidbPacket(0x8A0, 1, body, false, false)
}

func ParseGroupKickMemberResp(data []byte) error {
func ParseKickGroupMemberResp(data []byte) error {
return CheckTypedError[oidb.OidbSvcTrpcTcp0X8A0_1Response](data)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb"
)

func BuildGroupSetAdminReq(groupUin uint32, uid string, isAdmin bool) (*Packet, error) {
func BuildSetGroupAdminReq(groupUin uint32, uid string, isAdmin bool) (*Packet, error) {
body := &oidb.OidbSvcTrpcTcp0X1096_1{
GroupUin: groupUin,
Uid: uid,
Expand All @@ -13,6 +13,6 @@ func BuildGroupSetAdminReq(groupUin uint32, uid string, isAdmin bool) (*Packet,
return BuildOidbPacket(0x1096, 1, body, false, false)
}

func ParseGroupSetAdminResp(data []byte) error {
func ParseSetGroupAdminResp(data []byte) error {
return CheckError(data)
}
Loading

0 comments on commit 96210f1

Please sign in to comment.