implement some onebot actions (#26)
* feat: implement more group admin action (kick members and set search and set add type) * feat: implement some user extend func (set group mark \\ get custom emoji) * feat: implement get send emoji his
This commit is contained in:
1 parent
bf0a89e221
commit
df5e3a26ac
7 files changed
+300
-1
No files matched your search
@@ -9,10 +9,13 @@ import { computeHashes, computeMd5, loadBinarySource } from './highway/utils';
|
||||
import { buildSendElems } from './builders/element-builder';
|
||||
import { parseMsgPush } from './handlers/msg-push-handler';
|
||||
import type { ForwardNodePayload, MessageElement } from './events';
|
||||
import { createLogger } from '../utils/logger';
|
||||
import { PushMsgSchema } from './proto/message';
|
||||
import {
|
||||
OidbMuteMemberSchema,
|
||||
OidbMuteAllSchema,
|
||||
Oidb0x89a_0AddOptionSchema,
|
||||
Oidb0x89a_0SearchSchema,
|
||||
OidbKickMemberSchema,
|
||||
OidbLeaveGroupSchema,
|
||||
OidbFriendRequestActionSchema,
|
||||
@@ -49,6 +52,10 @@ import {
|
||||
OidbSetProfileSchema,
|
||||
Oidb0x7edReqSchema,
|
||||
Oidb0x7edRespSchema,
|
||||
Oidb0x8a0ReqSchema,
|
||||
Oidb0x8a0RespSchema,
|
||||
Oidb0xf16ReqSchema,
|
||||
Oidb0xf16RespSchema,
|
||||
Oidb0x8a7RespSchema,
|
||||
Oidb0x8a7ReqSchema,
|
||||
Oidb0xe17RespSchema,
|
||||
@@ -65,6 +72,10 @@ import {
|
||||
Oidb0x112eRespSchema,
|
||||
Oidb0xeb7ReqSchema,
|
||||
Oidb0xeb7RespSchema,
|
||||
FaceroamOpReqSchema,
|
||||
FaceroamOpRespSchema,
|
||||
Oidb0x9083ReqSchema,
|
||||
Oidb0x9083RespSchema,
|
||||
} from './proto/oidb-action';
|
||||
import { FileUploadExtSchema } from './proto/highway';
|
||||
import {
|
||||
@@ -76,6 +87,8 @@ import {
|
||||
} from './proto/longmsg';
|
||||
import { gzipSync, gunzipSync } from 'zlib';
|
||||
|
||||
const log = createLogger('BridgeActions');
|
||||
|
||||
export interface GroupFileInfo {
|
||||
fileId: string;
|
||||
fileName: string;
|
||||
@@ -407,6 +420,11 @@ export async function setFriendRemark(bridge: Bridge, userId: number, remark: st
|
||||
{ targetUid: uid, remark }, OidbSetFriendRemarkSchema);
|
||||
}
|
||||
|
||||
export async function setGroupRemark(bridge: Bridge, groupId: number, remark: string): Promise<void> {
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0xf16_1', 0xF16, 1,
|
||||
{ inner: { groupId: BigInt(groupId), remark }, field12: 0 }, Oidb0xf16ReqSchema);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Group file count
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -438,12 +456,28 @@ export async function muteGroupAll(bridge: Bridge, groupId: number, enable: bool
|
||||
{ groupUin: groupId, muteState: { state: enable ? 0xFFFFFFFF : 0 } }, OidbMuteAllSchema);
|
||||
}
|
||||
|
||||
export async function setGroupAddOption(bridge: Bridge, groupId: number, addType: number): Promise<void> {
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0x89a_0', 0x89A, 0,
|
||||
{ groupUin: BigInt(groupId), settings: { addType }, field12: 0 }, Oidb0x89a_0AddOptionSchema);
|
||||
}
|
||||
|
||||
export async function setGroupSearch(bridge: Bridge, groupId: number): Promise<void> {
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0x89a_0', 0x89A, 0,
|
||||
{ groupUin: BigInt(groupId), settings: new Uint8Array(0), field12: 0 }, Oidb0x89a_0SearchSchema);
|
||||
}
|
||||
|
||||
export async function kickGroupMember(bridge: Bridge, groupId: number, userId: number, reject: boolean, reason = ''): Promise<void> {
|
||||
const uid = await resolveUserUid(bridge, userId, groupId);
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0x8a0_1', 0x8A0, 1,
|
||||
{ groupUin: groupId, targetUid: uid, rejectAddRequest: reject, reason }, OidbKickMemberSchema);
|
||||
}
|
||||
|
||||
export async function kickGroupMembers(bridge: Bridge, groupId: number, userIds: number[], reject: boolean): Promise<void> {
|
||||
const targetUids = await Promise.all(userIds.map(userId => resolveUserUid(bridge, userId, groupId)));
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0x8a0_1', 0x8A0, 1,
|
||||
{ groupId: BigInt(groupId), targetUids, rejectAddRequest: reject ? 1 : 0, kickReason: new Uint8Array(0), field12: 0 }, Oidb0x8a0ReqSchema);
|
||||
}
|
||||
|
||||
export async function leaveGroup(bridge: Bridge, groupId: number): Promise<void> {
|
||||
await sendOidbAndCheck(bridge, 'OidbSvcTrpcTcp.0x1097_1', 0x1097, 1,
|
||||
{ groupUin: groupId }, OidbLeaveGroupSchema);
|
||||
@@ -1732,3 +1766,49 @@ export async function setAvatar(
|
||||
await uploadHighwayHttp(bridge, session, 90, loaded.bytes, hashes.md5, new Uint8Array(0));
|
||||
}
|
||||
|
||||
export async function fetchCustomFace(bridge: Bridge, count: number = 10): Promise<string[]> {
|
||||
const req = {
|
||||
inner: { field1: 1, osVersion: '10.0.26200', qqVersion: '9.9.28-46928' },
|
||||
uin: BigInt(bridge.qqInfo.uin),
|
||||
field3: 1,
|
||||
field6: 1,
|
||||
};
|
||||
const request = protoEncode(req, FaceroamOpReqSchema);
|
||||
const result = await bridge.sendRawPacket('Faceroam.OpReq', request);
|
||||
if (!result.success || !result.gotResponse || !result.responseData) {
|
||||
throw new Error(result.errorMessage || 'fetch custom face failed');
|
||||
}
|
||||
const resp = protoDecode(result.responseData, FaceroamOpRespSchema);
|
||||
if (!resp || (resp as any).retCode !== 0) {
|
||||
throw new Error(`fetch custom face error: ${(resp as any)?.message || 'unknown'}`);
|
||||
}
|
||||
const faceIds = (resp as any).item?.faceIds || [];
|
||||
return faceIds.slice(0, count).map((id: string) => `https://p.qpic.cn/qq_expression/${bridge.qqInfo.uin}/${id}/0`);
|
||||
}
|
||||
|
||||
export async function getEmojiLikes(
|
||||
bridge: Bridge,
|
||||
groupId: number,
|
||||
sequence: number,
|
||||
emojiId: string,
|
||||
emojiType: number = 1,
|
||||
count: number = 10,
|
||||
cookie: string = ''
|
||||
): Promise<{ users: Array<{ uin: number }>, cookie: string, isLast: boolean }> {
|
||||
const req = {
|
||||
groupId: BigInt(groupId),
|
||||
sequence,
|
||||
emojiType,
|
||||
emojiId,
|
||||
cookie: cookie ? Buffer.from(cookie, 'base64') : new Uint8Array(0),
|
||||
field7: 0,
|
||||
count,
|
||||
field12: 1,
|
||||
};
|
||||
const resp = await sendOidbAndDecode<any>(bridge, 'OidbSvcTrpcTcp.0x9083_1', 0x9083, 1, req, Oidb0x9083ReqSchema, Oidb0x9083RespSchema);
|
||||
const uin = resp?.inner?.userInfo?.uin;
|
||||
const users = uin ? [{ uin: Number(uin) }] : [];
|
||||
const respCookie = resp?.cookie ? Buffer.from(resp.cookie).toString('base64') : '';
|
||||
return { users, cookie: respCookie, isLast: !respCookie };
|
||||
}
|
||||
|
||||
@@ -30,7 +30,10 @@ import type { WebHonorType } from './web/group-honor';
|
||||
import {
|
||||
muteGroupMember as muteGroupMember_,
|
||||
muteGroupAll as muteGroupAll_,
|
||||
setGroupAddOption as setGroupAddOption_,
|
||||
setGroupSearch as setGroupSearch_,
|
||||
kickGroupMember as kickGroupMember_,
|
||||
kickGroupMembers as kickGroupMembers_,
|
||||
leaveGroup as leaveGroup_,
|
||||
setGroupAdmin as setGroupAdmin_,
|
||||
setGroupCard as setGroupCard_,
|
||||
@@ -64,6 +67,7 @@ import {
|
||||
markPrivateMessageRead as markGroupMsgAsRead_,
|
||||
markGroupMessageRead as markPrivateMsgAsRead_,
|
||||
setFriendRemark as setFriendRemark_,
|
||||
setGroupRemark as setGroupRemark_,
|
||||
fetchGroupFileCount as fetchGroupFileCount_,
|
||||
setOnlineStatus as setOnlineStatus_,
|
||||
setProfile as setProfile_,
|
||||
@@ -77,6 +81,8 @@ import {
|
||||
clickInlineKeyboardButton as clickInlineKeyboardButton_,
|
||||
sendGroupSign as sendGroupSign_,
|
||||
setAvatar as setAvatar_,
|
||||
fetchCustomFace as fetchCustomFace_,
|
||||
getEmojiLikes as getEmojiLikes_,
|
||||
} from './bridge-actions';
|
||||
import {
|
||||
getGroupHonorInfo as getGroupHonorInfo_,
|
||||
@@ -512,7 +518,10 @@ export class Bridge {
|
||||
|
||||
async muteGroupMember(groupId: number, userId: number, duration: number): Promise<void> { return muteGroupMember_(this, groupId, userId, duration); }
|
||||
async muteGroupAll(groupId: number, enable: boolean): Promise<void> { return muteGroupAll_(this, groupId, enable); }
|
||||
async setGroupAddOption(groupId: number, addType: number): Promise<void> { return setGroupAddOption_(this, groupId, addType); }
|
||||
async setGroupSearch(groupId: number): Promise<void> { return setGroupSearch_(this, groupId); }
|
||||
async kickGroupMember(groupId: number, userId: number, reject: boolean, reason = ''): Promise<void> { return kickGroupMember_(this, groupId, userId, reject, reason); }
|
||||
async kickGroupMembers(groupId: number, userIds: number[], reject: boolean): Promise<void> { return kickGroupMembers_(this, groupId, userIds, reject); }
|
||||
async leaveGroup(groupId: number): Promise<void> { return leaveGroup_(this, groupId); }
|
||||
async setGroupAdmin(groupId: number, userId: number, enable: boolean): Promise<void> { return setGroupAdmin_(this, groupId, userId, enable); }
|
||||
async setGroupCard(groupId: number, userId: number, card: string): Promise<void> { return setGroupCard_(this, groupId, userId, card); }
|
||||
@@ -550,6 +559,7 @@ export class Bridge {
|
||||
async markGroupMsgAsRead(groupId: number, sequence: number): Promise<void> { return markGroupMsgAsRead_(this, groupId, sequence); }
|
||||
async markPrivateMsgAsRead(userId: number, sequence: number): Promise<void> { return markPrivateMsgAsRead_(this, userId, sequence); }
|
||||
async setFriendRemark(userId: number, remark: string): Promise<void> { return setFriendRemark_(this, userId, remark); }
|
||||
async setGroupRemark(groupId: number, remark: string): Promise<void> { return setGroupRemark_(this, groupId, remark); }
|
||||
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
||||
return getGroupHonorInfo_(this, groupId, type);
|
||||
}
|
||||
@@ -616,6 +626,12 @@ export class Bridge {
|
||||
async setAvatar(source: string): Promise<void> {
|
||||
return setAvatar_(this, source);
|
||||
}
|
||||
async fetchCustomFace(count?: number): Promise<string[]> {
|
||||
return fetchCustomFace_(this, count);
|
||||
}
|
||||
async getEmojiLikes(groupId: number, sequence: number, emojiId: string, emojiType?: number, count?: number, cookie?: string) {
|
||||
return getEmojiLikes_(this, groupId, sequence, emojiId, emojiType, count, cookie);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Module-level helper functions ---
|
||||
|
||||
@@ -28,6 +28,26 @@ export const OidbMuteAllSchema = {
|
||||
muteState: { field: 2, type: 'message' as const, schema: OidbMuteAllStateSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x89A_0: Set group add option ---
|
||||
|
||||
export const Oidb0x89a_0AddOptionSettingsSchema = {
|
||||
addType: { field: 16, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const Oidb0x89a_0AddOptionSchema = {
|
||||
groupUin: { field: 1, type: 'uint64' as const },
|
||||
settings: { field: 2, type: 'message' as const, schema: Oidb0x89a_0AddOptionSettingsSchema },
|
||||
field12: { field: 12, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x89A_0: Set group search ---
|
||||
|
||||
export const Oidb0x89a_0SearchSchema = {
|
||||
groupUin: { field: 1, type: 'uint64' as const },
|
||||
settings: { field: 2, type: 'bytes' as const },
|
||||
field12: { field: 12, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x8A0_1: Kick group member ---
|
||||
|
||||
export const OidbKickMemberSchema = {
|
||||
@@ -1018,4 +1038,86 @@ export const Oidb0xeb7ReqSchema = {
|
||||
signInInfo: { field: 2, type: 'message' as const, schema: Oidb0xeb7SignInInfoSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const Oidb0xeb7RespSchema = {} satisfies ProtoSchema;
|
||||
export const Oidb0xeb7RespSchema = {} satisfies ProtoSchema;
|
||||
|
||||
// --- Faceroam.OpReq: Fetch custom face ---
|
||||
|
||||
export const FaceroamOpReqInnerSchema = {
|
||||
field1: { field: 1, type: 'uint32' as const },
|
||||
osVersion: { field: 2, type: 'string' as const },
|
||||
qqVersion: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FaceroamOpReqSchema = {
|
||||
inner: { field: 1, type: 'message' as const, schema: FaceroamOpReqInnerSchema },
|
||||
uin: { field: 2, type: 'uint64' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
field6: { field: 6, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FaceroamOpRespItemSchema = {
|
||||
faceIds: { field: 1, type: 'repeated_string' as const },
|
||||
category: { field: 3, type: 'string' as const },
|
||||
totalCount: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const FaceroamOpRespSchema = {
|
||||
retCode: { field: 1, type: 'uint32' as const },
|
||||
message: { field: 2, type: 'string' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
item: { field: 4, type: 'message' as const, schema: FaceroamOpRespItemSchema },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x9083_1: Get emoji likes ---
|
||||
|
||||
export const Oidb0x9083ReqSchema = {
|
||||
groupId: { field: 2, type: 'uint64' as const },
|
||||
sequence: { field: 3, type: 'uint32' as const },
|
||||
emojiType: { field: 4, type: 'uint32' as const },
|
||||
emojiId: { field: 5, type: 'string' as const },
|
||||
cookie: { field: 6, type: 'bytes' as const },
|
||||
field7: { field: 7, type: 'uint32' as const },
|
||||
count: { field: 8, type: 'uint32' as const },
|
||||
field12: { field: 12, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const Oidb0x9083RespUserInfoSchema = {
|
||||
uin: { field: 1, type: 'uint64' as const },
|
||||
field3: { field: 3, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const Oidb0x9083RespInnerSchema = {
|
||||
userInfo: { field: 1, type: 'message' as const, schema: Oidb0x9083RespUserInfoSchema },
|
||||
field4: { field: 4, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const Oidb0x9083RespSchema = {
|
||||
inner: { field: 4, type: 'message' as const, schema: Oidb0x9083RespInnerSchema },
|
||||
cookie: { field: 5, type: 'bytes' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
// --- 0x8a0_1: Kick group members (batch) ---
|
||||
|
||||
export const Oidb0x8a0ReqSchema = {
|
||||
groupId: { field: 1, type: 'uint64' as const },
|
||||
targetUids: { field: 3, type: 'repeated_string' as const },
|
||||
rejectAddRequest: { field: 4, type: 'uint32' as const },
|
||||
kickReason: { field: 5, type: 'bytes' as const },
|
||||
field12: { field: 12, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const Oidb0x8a0RespSchema = {} satisfies ProtoSchema;
|
||||
|
||||
// --- 0xf16_1: Set group remark ---
|
||||
|
||||
export const Oidb0xf16InnerSchema = {
|
||||
groupId: { field: 1, type: 'uint64' as const },
|
||||
remark: { field: 3, type: 'string' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const Oidb0xf16ReqSchema = {
|
||||
inner: { field: 1, type: 'message' as const, schema: Oidb0xf16InnerSchema },
|
||||
field12: { field: 12, type: 'uint32' as const },
|
||||
} satisfies ProtoSchema;
|
||||
|
||||
export const Oidb0xf16RespSchema = {} satisfies ProtoSchema;
|
||||
Reference in new issue
Block a user