Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 获取剩余@全员次数 & fix #126

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/internal/network/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (t *Transport) readSSOFrame(resp *Response, payload []byte) error {
err = errors.Errorf("return code unsuccessful: %d", retCode)
}
if err != nil {
return errors.Errorf("%s %s", err.Error(), resp.Message)
return errors.Wrap(err, resp.Message)
}
resp.CommandName = head.ReadStringWithLength("u32", true)
if resp.CommandName == "Heartbeat.Alive" {
Expand Down
14 changes: 14 additions & 0 deletions client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,3 +1349,17 @@ func (c *QQClient) CheckURLSafely(url string) (oidb2.URLSecurityLevel, error) {
}
return oidb2.ParseURLCheckResponse(resp)
}

// 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)
if err != nil {
return nil, err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return nil, err
}
return oidb2.ParseAtAllRemainResponse(resp)
}
35 changes: 35 additions & 0 deletions client/packets/oidb/group_atall_remain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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) {
body := &oidb.OidbSvcTrpcTcp0X8A7_0_ReqBody{
SubCmd: 1,
LimitIntervalTypeForUin: 2,
LimitIntervalTypeForGroup: 1,
Uin: uint64(uin),
GroupUin: uint64(gin),
}
return BuildOidbPacket(0x8A7, 0, body, false, true)
}

type AtAllRemainInfo struct {
CanAtAll bool
CountForGroup uint32 // 当前群默认可用次数
CountForUin uint32 // 当前QQ剩余次数
}

// ref https://github.com/Mrs4s/MiraiGo/blob/54bdd873e3fed9fe1c944918924674dacec5ac76/client/group_msg.go#L326
func ParseAtAllRemainResponse(data []byte) (*AtAllRemainInfo, error) {
var rsp oidb.OidbSvcTrpcTcp0X8A7_0_RspBody
_, err := ParseOidbPacket(data, &rsp)
if err != nil {
return nil, err
}
return &AtAllRemainInfo{
CanAtAll: rsp.CanAtAll,
CountForGroup: rsp.CountForGroup,
CountForUin: rsp.CountForUin,
}, nil
}
26 changes: 14 additions & 12 deletions client/packets/oidb/security_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package oidb
import (
"errors"

"github.com/RomiChan/protobuf/proto"

"github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb"
)

// see https://github.com/Mrs4s/MiraiGo/blob/master/client/security.go
// ref https://github.com/Mrs4s/MiraiGo/blob/master/client/security.go

type URLSecurityLevel int

Expand All @@ -33,16 +35,16 @@ func BuildURLCheckRequest(botuin uint32, url string) (*Packet, error) {
body := &oidb.OidbSvcTrpcTcp0XBCB_0_ReqBody{
CheckUrlReq: &oidb.CheckUrlReq{
Url: []string{url},
QqPfTo: "mqq.group",
Type: 2,
SendUin: uint64(botuin),
ReqType: "webview",
OriginalUrl: url,
IsArk: false,
IsFinish: false,
QqPfTo: proto.String("mqq.group"),
Type: proto.Uint32(2),
SendUin: proto.Uint64(uint64(botuin)),
ReqType: proto.String("webview"),
OriginalUrl: proto.String(url),
IsArk: proto.Bool(false),
IsFinish: proto.Bool(false),
SrcUrls: []string{url},
SrcPlatform: 1,
Qua: "AQQ_2013 4.6/2013 8.4.184945&NA_0/000000&ADR&null18&linux&2017&C2293D02BEE31158&7.1.2&V3",
SrcPlatform: proto.Uint32(1),
Qua: proto.String("AQQ_2013 4.6/2013 8.4.184945&NA_0/000000&ADR&null18&linux&2017&C2293D02BEE31158&7.1.2&V3"),
},
}
return BuildOidbPacket(0xBCB, 0, body, false, false)
Expand All @@ -57,10 +59,10 @@ func ParseURLCheckResponse(data []byte) (URLSecurityLevel, error) {
if rsp.CheckUrlRsp == nil || len(rsp.CheckUrlRsp.Results) == 0 {
return URLSecurityLevelUnknown, errors.New("response is empty")
}
if rsp.CheckUrlRsp.Results[0].JumpUrl != "" {
if rsp.CheckUrlRsp.Results[0].JumpUrl.IsSome() {
return URLSecurityLevelDanger, nil
}
if rsp.CheckUrlRsp.Results[0].Umrtype == 2 {
if rsp.CheckUrlRsp.Results[0].UmrType.Unwrap() == 2 {
return URLSecurityLevelSafe, nil
}
return URLSecurityLevelUnknown, nil
Expand Down
20 changes: 20 additions & 0 deletions client/packets/pb/service/oidb/OidbSvcTrpcTcp0x8A7_0.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions client/packets/pb/service/oidb/OidbSvcTrpcTcp0x8A7_0.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

// ref https://github.com/Mrs4s/MiraiGo/blob/master/client/pb/oidb/oidb0x8a7.proto

option go_package = "github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb";

message OidbSvcTrpcTcp0x8A7_0_ReqBody {
uint32 subCmd = 1;
uint32 limitIntervalTypeForUin = 2;
uint32 limitIntervalTypeForGroup = 3;
uint64 uin = 4;
uint64 groupUin = 5;
}

message OidbSvcTrpcTcp0x8A7_0_RspBody {
bool canAtAll = 1;
uint32 countForUin = 2;
uint32 countForGroup = 3;
//optional bytes promptMsg1 = 4;
//optional bytes promptMsg2 = 5;
}
68 changes: 36 additions & 32 deletions client/packets/pb/service/oidb/OidbSvcTrpcTcp0xBCB_0.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 39 additions & 39 deletions client/packets/pb/service/oidb/OidbSvcTrpcTcp0xBCB_0.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,63 @@ syntax = "proto3";
option go_package = "github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb";

message OidbSvcTrpcTcp0xBCB_0_ReqBody {
int32 notUseCache = 9;
CheckUrlReq checkUrlReq = 10;
optional int32 notUseCache = 9;
optional CheckUrlReq checkUrlReq = 10;
}

message CheckUrlReq {
repeated string url = 1;
string refer = 2;
string plateform = 3;
string qqPfTo = 4;
uint32 type = 5;
uint32 from = 6;
uint64 chatid = 7;
uint64 serviceType = 8;
uint64 sendUin = 9;
string reqType = 10;
string originalUrl = 11;
bool isArk = 12;
string arkName = 13;
bool isFinish = 14;
optional string refer = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解释一下为什么这么改

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解释一下为什么这么改

miraigo就是这么写的 Mrs4s: MiraiGo/client/pb/oidb/oidb0xbcb.proto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你应该问为什么之前不是这么写的😊

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有区别吗?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再有这种无意义的提交,我不介意把你block掉

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有时间格式化,不如去加个ci配置,让他自动化

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有时间格式化,不如去加个ci配置,让他自动化

ide 自动 关我什么事

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有区别吗?

改错代码 (误删optional) 回滚一下 可 ?

optional string plateform = 3;
optional string qqPfTo = 4;
optional uint32 type = 5;
optional uint32 from = 6;
optional uint64 chatId = 7;
optional uint64 serviceType = 8;
optional uint64 sendUin = 9;
optional string reqType = 10;
optional string originalUrl = 11;
optional bool isArk = 12;
optional string arkName = 13;
optional bool isFinish = 14;
repeated string srcUrls = 15;
uint32 srcPlatform = 16;
string qua = 17;
optional uint32 srcPlatform = 16;
optional string qua = 17;
}

message OidbSvcTrpcTcp0xBCB_0_RspBody {
string wording = 1;
CheckUrlRsp checkUrlRsp = 10;
optional string wording = 1;
optional CheckUrlRsp checkUrlRsp = 10;
}

message CheckUrlRsp {
repeated UrlCheckResult results = 1;
uint32 nextReqDuration = 2;
optional uint32 nextReqDuration = 2;
}

message UrlCheckResult {
string url = 1;
uint32 result = 2;
uint32 jumpResult = 3;
string jumpUrl = 4;
uint32 level = 5;
uint32 subLevel = 6;
uint32 umrtype = 7;
uint32 retFrom = 8;
uint64 operationBit = 9;
optional string url = 1;
optional uint32 result = 2;
optional uint32 jumpResult = 3;
optional string jumpUrl = 4;
optional uint32 level = 5;
optional uint32 subLevel = 6;
optional uint32 umrType = 7;
optional uint32 retFrom = 8;
optional uint64 operationBit = 9;
}

/*
message CheckUrlReqItem {
string url = 1;
string refer = 2;
string plateform = 3;
string qqPfTo = 4;
uint32 type = 5;
uint32 from = 6;
uint64 chatid = 7;
uint64 serviceType = 8;
uint64 sendUin = 9;
string reqType = 10;
optional string url = 1;
optional string refer = 2;
optional string plateform = 3;
optional string qqPfTo = 4;
optional uint32 type = 5;
optional uint32 from = 6;
optional uint64 chatId = 7;
optional uint64 serviceType = 8;
optional uint64 sendUin = 9;
optional string reqType = 10;
}
*/