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: 群打卡 #122

Merged
merged 4 commits into from
Nov 14, 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
13 changes: 13 additions & 0 deletions client/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,3 +1280,16 @@ func (c *QQClient) ImageOcr(url string) (*oidb2.OcrResponse, error) {
}
return nil, errors.New("image error")
}

// SendGroupSign 发送群聊打卡消息
func (c *QQClient) SendGroupSign(groupUin uint32) (*oidb2.BotGroupClockInResult, error) {
pkt, err := oidb2.BuildGroupSignPacket(c.Uin, groupUin, c.version().CurrentVersion)
if err != nil {
return nil, err
}
resp, err := c.sendOidbPacketAndWait(pkt)
if err != nil {
return nil, err
}
return oidb2.ParseGroupSignResp(resp)
}
54 changes: 54 additions & 0 deletions client/packets/oidb/group_sign.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package oidb

import (
"errors"
"strconv"

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

// 群打卡

type BotGroupClockInResult struct {
Title string // 今日已成功打卡
KeepDayText string // 已打卡N天
GroupRankText string // 群内排名第N位
ClockInUtcTime int64 // 打卡时间
DetailURL string // Detail info url https://qun.qq.com/v2/signin/detail?...
}

func BuildGroupSignPacket(botUin, groupUin uint32, appVersion string) (*Packet, error) {
body := &oidb.OidbSvcTrpcTcp0XEB7_1_ReqBody{
SignInWriteReq: &oidb.StSignInWriteReq{
Uin: strconv.Itoa(int(botUin)),
GroupUin: strconv.Itoa(int(groupUin)),
AppVersion: appVersion,
},
}
return BuildOidbPacket(0xEB7, 1, body, false, false)
}

func ParseGroupSignResp(data []byte) (*BotGroupClockInResult, error) {
var rsp oidb.OidbSvcTrpcTcp0XEB7_1_RspBody
_, err := ParseOidbPacket(data, &rsp)
if err != nil {
return nil, err
}

if rsp.SignInWriteRsp == nil || rsp.SignInWriteRsp.DoneInfo == nil {
return nil, errors.New("SignInWriteRsp or SignInWriteRsp.DoneInfo nil")
}

ret := &BotGroupClockInResult{
Title: rsp.SignInWriteRsp.DoneInfo.Title,
KeepDayText: rsp.SignInWriteRsp.DoneInfo.KeepDayText,
DetailURL: rsp.SignInWriteRsp.DoneInfo.DetailUrl,
}
if size := len(rsp.SignInWriteRsp.DoneInfo.ClockInInfo); size > 0 {
ret.GroupRankText = rsp.SignInWriteRsp.DoneInfo.ClockInInfo[0]
if size > 1 {
ret.ClockInUtcTime, _ = strconv.ParseInt(rsp.SignInWriteRsp.DoneInfo.ClockInInfo[1], 10, 64)
}
}
return ret, nil
}
33 changes: 33 additions & 0 deletions client/packets/pb/service/oidb/OidbSvcTrpcTcp0xEB7_1.pb.go

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

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

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

// see https://github.com/LagrangeDev/Lagrange.Core/blob/47b819d43ad101a1a066a3f8afa094d000fe19f5/Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0xEB7_1.cs

message OidbSvcTrpcTcp0xEB7_1_ReqBody {
optional StSignInWriteReq signInWriteReq = 2;
}

message StSignInWriteReq {
string Uin = 1;
string GroupUin = 2;
string AppVersion = 3; // 不确定要不要加,测试过没有这个参数也是可以的
}

message OidbSvcTrpcTcp0xEB7_1_RspBody {
optional StSignInWriteRsp signInWriteRsp = 2;
}

message StSignInWriteRsp {
optional SignInStatusDoneInfo doneInfo = 2;
}

message SignInStatusDoneInfo {
string Title = 1; // 今日已成功打卡
string KeepDayText = 2; // 已打卡N天
repeated string ClockInInfo = 3; // ["群内排名第N位", "[clock in timestamp (second)]"]
string DetailUrl = 4; // https://qun.qq.com/v2/signin/detail?...
}