refactor(api): move 14 group-admin methods to GroupAdminApi (#6 commit 3/13)
Third of 13 commits. Folds the previous `actions/group-admin.ts`
plus the matching Bridge facade methods into a typed `apis.groupAdmin`
hub.
Methods (14, all renamed to drop the redundant `Group` prefix once
the `apis.groupAdmin` namespace makes it implicit):
muteGroupMember → apis.groupAdmin.muteMember
muteGroupAll → apis.groupAdmin.muteAll
setGroupAddOption → apis.groupAdmin.setAddOption
setGroupSearch → apis.groupAdmin.setSearch
setGroupAddRequest → apis.groupAdmin.setAddRequest
kickGroupMember → apis.groupAdmin.kickMember
kickGroupMembers → apis.groupAdmin.kickMembers
leaveGroup → apis.groupAdmin.leave
setGroupAdmin → apis.groupAdmin.setAdmin
setGroupCard → apis.groupAdmin.setCard
setGroupName → apis.groupAdmin.setName
setGroupSpecialTitle→ apis.groupAdmin.setSpecialTitle
setGroupRemark → apis.groupAdmin.setRemark
getGroupAtAllRemain → apis.groupAdmin.getAtAllRemain
actions/group-admin.ts deleted. The corresponding `*_` alias imports
and `async xxx() { return xxx_(this, …); }` delegate methods on
Bridge are gone.
Caller updates
--------------
* onebot/instance-context.ts — 6 sites (the multi-method binding for
the OneBot action layer).
* onebot/actions/extended.ts — 8 sites including `getAtAllRemain`.
* onebot/actions/group-admin.ts — all 6 onebot action handlers.
* onebot/modules/request-actions.ts — `setGroupAddRequest`.
Test updates
------------
* tests/actions/group-admin.test.ts — was importing the deleted
`* as admin` module and calling `admin.muteGroupMember(bridge, ...)`.
Switched to `new GroupAdminApi(bridge as any).muteMember(...)` —
same wire validation, just constructs the real Api class once per
call (the Api is stateless so it's effectively free).
* tests/onebot/request-actions.test.ts — was stubbing
`setGroupAddRequest` flat on bridge. Updated to
`apis: { groupAdmin: { setAddRequest } } as any`.
Tests: 587/587 pass (network-manager native-addon failure unchanged).
This commit is contained in:
@@ -1,162 +0,0 @@
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
import { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
Oidb0x89a_0AddOption,
|
||||
Oidb0x89a_0Search,
|
||||
Oidb0x8a0Req,
|
||||
Oidb0x8a7Req,
|
||||
Oidb0x8a7Resp,
|
||||
Oidb0xf16Req,
|
||||
OidbGroupRequestAction,
|
||||
OidbKickMember,
|
||||
OidbLeaveGroup,
|
||||
OidbMuteAll,
|
||||
OidbMuteMember,
|
||||
OidbRenameGroup,
|
||||
OidbRenameMember,
|
||||
OidbSetAdmin,
|
||||
OidbSpecialTitle,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
|
||||
// ─────────────── mute / un-mute ───────────────
|
||||
|
||||
export async function muteGroupMember(bridge: Bridge, groupId: number, userId: number, duration: number): Promise<void> {
|
||||
const uid = await bridge.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbMuteMember>(0x1253, 1, {
|
||||
groupUin: groupId, type: 1, body: { targetUid: uid, duration },
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1253_1', protobuf_encode<OidbBase<OidbMuteMember>>(env));
|
||||
}
|
||||
|
||||
export async function muteGroupAll(bridge: Bridge, groupId: number, enable: boolean): Promise<void> {
|
||||
const env = makeOidbEnvelope<OidbMuteAll>(0x89A, 0, {
|
||||
groupUin: groupId, muteState: { state: enable ? 0xFFFFFFFF : 0 },
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<OidbMuteAll>>(env));
|
||||
}
|
||||
|
||||
// ─────────────── join-policy ───────────────
|
||||
|
||||
export async function setGroupAddOption(bridge: Bridge, groupId: number, addType: number): Promise<void> {
|
||||
const env = makeOidbEnvelope<Oidb0x89a_0AddOption>(0x89A, 0, {
|
||||
groupUin: BigInt(groupId), settings: { addType }, field12: 0,
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<Oidb0x89a_0AddOption>>(env));
|
||||
}
|
||||
|
||||
export async function setGroupSearch(bridge: Bridge, groupId: number): Promise<void> {
|
||||
const env = makeOidbEnvelope<Oidb0x89a_0Search>(0x89A, 0, {
|
||||
groupUin: BigInt(groupId), settings: new Uint8Array(0), field12: 0,
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<Oidb0x89a_0Search>>(env));
|
||||
}
|
||||
|
||||
export async function setGroupAddRequest(
|
||||
bridge: Bridge, groupId: number, sequence: number, eventType: number,
|
||||
approve: boolean, reason = '', filtered = false,
|
||||
): Promise<void> {
|
||||
const subCmd = filtered ? 2 : 1;
|
||||
const cmd = filtered ? 'OidbSvcTrpcTcp.0x10c8_2' : 'OidbSvcTrpcTcp.0x10c8_1';
|
||||
const env = makeOidbEnvelope<OidbGroupRequestAction>(
|
||||
0x10C8, subCmd,
|
||||
{ accept: approve ? 1 : 2, body: { sequence: BigInt(sequence), eventType, groupUin: groupId, message: reason } },
|
||||
true,
|
||||
);
|
||||
await runOidb(bridge, cmd, protobuf_encode<OidbBase<OidbGroupRequestAction>>(env));
|
||||
}
|
||||
|
||||
// ─────────────── kick / leave ───────────────
|
||||
|
||||
export async function kickGroupMember(bridge: Bridge, groupId: number, userId: number, reject: boolean, reason = ''): Promise<void> {
|
||||
const uid = await bridge.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbKickMember>(0x8A0, 1, {
|
||||
groupUin: groupId, targetUid: uid, rejectAddRequest: reject, reason,
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a0_1', protobuf_encode<OidbBase<OidbKickMember>>(env));
|
||||
}
|
||||
|
||||
export async function kickGroupMembers(bridge: Bridge, groupId: number, userIds: number[], reject: boolean): Promise<void> {
|
||||
const targetUids = await Promise.all(userIds.map(userId => bridge.resolveUserUid(userId, groupId)));
|
||||
const env = makeOidbEnvelope<Oidb0x8a0Req>(0x8A0, 1, {
|
||||
groupId: BigInt(groupId), targetUids, rejectAddRequest: reject ? 1 : 0, kickReason: new Uint8Array(0), field12: 0,
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a0_1', protobuf_encode<OidbBase<Oidb0x8a0Req>>(env));
|
||||
}
|
||||
|
||||
export async function leaveGroup(bridge: Bridge, groupId: number): Promise<void> {
|
||||
const env = makeOidbEnvelope<OidbLeaveGroup>(0x1097, 1, { groupUin: groupId });
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1097_1', protobuf_encode<OidbBase<OidbLeaveGroup>>(env));
|
||||
}
|
||||
|
||||
// ─────────────── role / display name ───────────────
|
||||
|
||||
export async function setGroupAdmin(bridge: Bridge, groupId: number, userId: number, enable: boolean): Promise<void> {
|
||||
const uid = await bridge.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbSetAdmin>(0x1096, 1, { groupUin: groupId, uid, isAdmin: enable });
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1096_1', protobuf_encode<OidbBase<OidbSetAdmin>>(env));
|
||||
}
|
||||
|
||||
export async function setGroupCard(bridge: Bridge, groupId: number, userId: number, card: string): Promise<void> {
|
||||
const uid = await bridge.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbRenameMember>(0x8FC, 3, {
|
||||
groupUin: groupId, body: { targetUid: uid, targetName: card },
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8fc_3', protobuf_encode<OidbBase<OidbRenameMember>>(env));
|
||||
}
|
||||
|
||||
export async function setGroupName(bridge: Bridge, groupId: number, name: string): Promise<void> {
|
||||
const env = makeOidbEnvelope<OidbRenameGroup>(0x89A, 15, { groupUin: groupId, body: { targetName: name } });
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_15', protobuf_encode<OidbBase<OidbRenameGroup>>(env));
|
||||
}
|
||||
|
||||
export async function setGroupSpecialTitle(bridge: Bridge, groupId: number, userId: number, title: string): Promise<void> {
|
||||
const uid = await bridge.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbSpecialTitle>(0x8FC, 2, {
|
||||
groupUin: groupId, body: { targetUid: uid, specialTitle: title, expireTime: -1 },
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8fc_2', protobuf_encode<OidbBase<OidbSpecialTitle>>(env));
|
||||
}
|
||||
|
||||
// ─────────────── personal-side metadata ───────────────
|
||||
|
||||
// setGroupRemark is the bot's local-only label for the group; it lives
|
||||
// here rather than in friend.ts because the semantic is "operate on a
|
||||
// group" rather than "operate on a contact list".
|
||||
export async function setGroupRemark(bridge: Bridge, groupId: number, remark: string): Promise<void> {
|
||||
const env = makeOidbEnvelope<Oidb0xf16Req>(0xF16, 1, { inner: { groupId: BigInt(groupId), remark }, field12: 0 });
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0xf16_1', protobuf_encode<OidbBase<Oidb0xf16Req>>(env));
|
||||
}
|
||||
|
||||
// ─────────────── group-level quota query ───────────────
|
||||
|
||||
export async function getGroupAtAllRemain(
|
||||
bridge: Bridge,
|
||||
groupId: number,
|
||||
) {
|
||||
const req = {
|
||||
basic1: 1,
|
||||
basic2: 2,
|
||||
basic3: 1,
|
||||
uin: BigInt(bridge.identity.uin),
|
||||
groupId: BigInt(groupId),
|
||||
type: 0,
|
||||
};
|
||||
|
||||
const env = makeOidbEnvelope<Oidb0x8a7Req>(0x8A7, 0, req);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a7_0', protobuf_encode<OidbBase<Oidb0x8a7Req>>(env));
|
||||
const result = protobuf_decode<OidbBase<Oidb0x8a7Resp>>(respBytes).body;
|
||||
|
||||
if (!result) {
|
||||
throw new Error('get group at all remain result empty');
|
||||
}
|
||||
|
||||
// Cast numbers to plain Number: the OIDB layer may surface uint32 as
|
||||
// BigInt and the WebUI JSON serializer chokes on those.
|
||||
return {
|
||||
can_at_all: !!result.canAtAll,
|
||||
remain_at_all_count_for_group: Number(result.groupRemain || 0),
|
||||
remain_at_all_count_for_uin: Number(result.uinRemain || 0),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
// GroupAdminApi — mute/kick/admin/card/name/title/leave + join-policy
|
||||
// + add-request handling. Inlined from the previous
|
||||
// `actions/group-admin.ts` (deleted alongside the rest of the
|
||||
// actions/* facade in commit 13).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
Oidb0x89a_0AddOption,
|
||||
Oidb0x89a_0Search,
|
||||
Oidb0x8a0Req,
|
||||
Oidb0x8a7Req,
|
||||
Oidb0x8a7Resp,
|
||||
Oidb0xf16Req,
|
||||
OidbGroupRequestAction,
|
||||
OidbKickMember,
|
||||
OidbLeaveGroup,
|
||||
OidbMuteAll,
|
||||
OidbMuteMember,
|
||||
OidbRenameGroup,
|
||||
OidbRenameMember,
|
||||
OidbSetAdmin,
|
||||
OidbSpecialTitle,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { makeOidbEnvelope, runOidb } from '../bridge-oidb';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
export class GroupAdminApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
|
||||
async muteMember(groupId: number, userId: number, duration: number): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const uid = await this.ctx.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbMuteMember>(0x1253, 1, {
|
||||
groupUin: groupId, type: 1, body: { targetUid: uid, duration },
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1253_1', protobuf_encode<OidbBase<OidbMuteMember>>(env));
|
||||
}
|
||||
|
||||
async muteAll(groupId: number, enable: boolean): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbMuteAll>(0x89A, 0, {
|
||||
groupUin: groupId, muteState: { state: enable ? 0xFFFFFFFF : 0 },
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<OidbMuteAll>>(env));
|
||||
}
|
||||
|
||||
async setAddOption(groupId: number, addType: number): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<Oidb0x89a_0AddOption>(0x89A, 0, {
|
||||
groupUin: BigInt(groupId), settings: { addType }, field12: 0,
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<Oidb0x89a_0AddOption>>(env));
|
||||
}
|
||||
|
||||
async setSearch(groupId: number): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<Oidb0x89a_0Search>(0x89A, 0, {
|
||||
groupUin: BigInt(groupId), settings: new Uint8Array(0), field12: 0,
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_0', protobuf_encode<OidbBase<Oidb0x89a_0Search>>(env));
|
||||
}
|
||||
|
||||
async setAddRequest(
|
||||
groupId: number, sequence: number, eventType: number,
|
||||
approve: boolean, reason = '', filtered = false,
|
||||
): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const subCmd = filtered ? 2 : 1;
|
||||
const cmd = filtered ? 'OidbSvcTrpcTcp.0x10c8_2' : 'OidbSvcTrpcTcp.0x10c8_1';
|
||||
const env = makeOidbEnvelope<OidbGroupRequestAction>(
|
||||
0x10C8, subCmd,
|
||||
{ accept: approve ? 1 : 2, body: { sequence: BigInt(sequence), eventType, groupUin: groupId, message: reason } },
|
||||
true,
|
||||
);
|
||||
await runOidb(bridge, cmd, protobuf_encode<OidbBase<OidbGroupRequestAction>>(env));
|
||||
}
|
||||
|
||||
async kickMember(groupId: number, userId: number, reject: boolean, reason = ''): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const uid = await this.ctx.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbKickMember>(0x8A0, 1, {
|
||||
groupUin: groupId, targetUid: uid, rejectAddRequest: reject, reason,
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a0_1', protobuf_encode<OidbBase<OidbKickMember>>(env));
|
||||
}
|
||||
|
||||
async kickMembers(groupId: number, userIds: number[], reject: boolean): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const targetUids = await Promise.all(userIds.map(userId => this.ctx.resolveUserUid(userId, groupId)));
|
||||
const env = makeOidbEnvelope<Oidb0x8a0Req>(0x8A0, 1, {
|
||||
groupId: BigInt(groupId), targetUids, rejectAddRequest: reject ? 1 : 0, kickReason: new Uint8Array(0), field12: 0,
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a0_1', protobuf_encode<OidbBase<Oidb0x8a0Req>>(env));
|
||||
}
|
||||
|
||||
async leave(groupId: number): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbLeaveGroup>(0x1097, 1, { groupUin: groupId });
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1097_1', protobuf_encode<OidbBase<OidbLeaveGroup>>(env));
|
||||
}
|
||||
|
||||
async setAdmin(groupId: number, userId: number, enable: boolean): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const uid = await this.ctx.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbSetAdmin>(0x1096, 1, { groupUin: groupId, uid, isAdmin: enable });
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x1096_1', protobuf_encode<OidbBase<OidbSetAdmin>>(env));
|
||||
}
|
||||
|
||||
async setCard(groupId: number, userId: number, card: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const uid = await this.ctx.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbRenameMember>(0x8FC, 3, {
|
||||
groupUin: groupId, body: { targetUid: uid, targetName: card },
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8fc_3', protobuf_encode<OidbBase<OidbRenameMember>>(env));
|
||||
}
|
||||
|
||||
async setName(groupId: number, name: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<OidbRenameGroup>(0x89A, 15, { groupUin: groupId, body: { targetName: name } });
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x89a_15', protobuf_encode<OidbBase<OidbRenameGroup>>(env));
|
||||
}
|
||||
|
||||
async setSpecialTitle(groupId: number, userId: number, title: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const uid = await this.ctx.resolveUserUid(userId, groupId);
|
||||
const env = makeOidbEnvelope<OidbSpecialTitle>(0x8FC, 2, {
|
||||
groupUin: groupId, body: { targetUid: uid, specialTitle: title, expireTime: -1 },
|
||||
});
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0x8fc_2', protobuf_encode<OidbBase<OidbSpecialTitle>>(env));
|
||||
}
|
||||
|
||||
/**
|
||||
* The bot's local-only label for a group. Lives here rather than
|
||||
* `FriendApi` because the semantic is "operate on a group" rather
|
||||
* than "operate on a contact list".
|
||||
*/
|
||||
async setRemark(groupId: number, remark: string): Promise<void> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const env = makeOidbEnvelope<Oidb0xf16Req>(0xF16, 1, { inner: { groupId: BigInt(groupId), remark }, field12: 0 });
|
||||
await runOidb(bridge, 'OidbSvcTrpcTcp.0xf16_1', protobuf_encode<OidbBase<Oidb0xf16Req>>(env));
|
||||
}
|
||||
|
||||
async getAtAllRemain(groupId: number): Promise<{
|
||||
can_at_all: boolean;
|
||||
remain_at_all_count_for_group: number;
|
||||
remain_at_all_count_for_uin: number;
|
||||
}> {
|
||||
const bridge = asBridge(this.ctx);
|
||||
const req = {
|
||||
basic1: 1,
|
||||
basic2: 2,
|
||||
basic3: 1,
|
||||
uin: BigInt(this.ctx.identity.uin),
|
||||
groupId: BigInt(groupId),
|
||||
type: 0,
|
||||
};
|
||||
const env = makeOidbEnvelope<Oidb0x8a7Req>(0x8A7, 0, req);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x8a7_0', protobuf_encode<OidbBase<Oidb0x8a7Req>>(env));
|
||||
const result = protobuf_decode<OidbBase<Oidb0x8a7Resp>>(respBytes).body;
|
||||
if (!result) throw new Error('get group at all remain result empty');
|
||||
|
||||
// Cast numbers to plain Number: the OIDB layer may surface uint32
|
||||
// as BigInt and the WebUI JSON serializer chokes on those.
|
||||
return {
|
||||
can_at_all: !!result.canAtAll,
|
||||
remain_at_all_count_for_group: Number(result.groupRemain || 0),
|
||||
remain_at_all_count_for_uin: Number(result.uinRemain || 0),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { ContactsApi } from './contacts';
|
||||
import { GroupAdminApi } from './group-admin';
|
||||
import { MessageApi } from './message';
|
||||
|
||||
export interface ApiHub {
|
||||
@@ -29,8 +30,9 @@ export interface ApiHub {
|
||||
readonly message: MessageApi;
|
||||
/** Friend / group / member roster + user-profile + group-request-list + download-rkey. */
|
||||
readonly contacts: ContactsApi;
|
||||
/** Group moderation: mute/kick/admin/card/name/title/leave + join-policy. */
|
||||
readonly groupAdmin: GroupAdminApi;
|
||||
// Pending — added as later commits land:
|
||||
// readonly groupAdmin: GroupAdminApi;
|
||||
// readonly groupFile: GroupFileApi;
|
||||
// readonly groupAlbum: GroupAlbumApi;
|
||||
// readonly friend: FriendApi;
|
||||
@@ -54,6 +56,7 @@ export function buildApiHub(ctx: BridgeContext): ApiHub {
|
||||
return {
|
||||
message: new MessageApi(ctx),
|
||||
contacts: new ContactsApi(ctx),
|
||||
groupAdmin: new GroupAdminApi(ctx),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -61,4 +64,5 @@ export function buildApiHub(ctx: BridgeContext): ApiHub {
|
||||
// `import type { MessageApi } from '@snowluma/core/.../apis'` for
|
||||
// signature use. Concrete instances always come from `bridge.apis.*`.
|
||||
export { ContactsApi } from './contacts';
|
||||
export { GroupAdminApi } from './group-admin';
|
||||
export { MessageApi } from './message';
|
||||
|
||||
@@ -44,20 +44,7 @@ export interface BridgeInterface {
|
||||
|
||||
// ─── Fetch (contacts / profile / system) — moved to apis.contacts ───
|
||||
|
||||
// ─── Group admin ───
|
||||
muteGroupMember(groupId: number, userId: number, duration: number): Promise<void>;
|
||||
muteGroupAll(groupId: number, enable: boolean): Promise<void>;
|
||||
setGroupAddOption(groupId: number, addType: number): Promise<void>;
|
||||
setGroupSearch(groupId: number): Promise<void>;
|
||||
setGroupAddRequest(groupId: number, sequence: number, eventType: number, approve: boolean, reason?: string, filtered?: boolean): Promise<void>;
|
||||
kickGroupMember(groupId: number, userId: number, reject: boolean, reason?: string): Promise<void>;
|
||||
kickGroupMembers(groupId: number, userIds: number[], reject: boolean): Promise<void>;
|
||||
leaveGroup(groupId: number): Promise<void>;
|
||||
setGroupAdmin(groupId: number, userId: number, enable: boolean): Promise<void>;
|
||||
setGroupCard(groupId: number, userId: number, card: string): Promise<void>;
|
||||
setGroupName(groupId: number, name: string): Promise<void>;
|
||||
setGroupSpecialTitle(groupId: number, userId: number, title: string): Promise<void>;
|
||||
setGroupRemark(groupId: number, remark: string): Promise<void>;
|
||||
// ─── Group admin (moved to apis.groupAdmin) ───
|
||||
setGroupReaction(groupId: number, sequence: number, code: string, isSet: boolean): Promise<void>;
|
||||
setGroupEssence(groupId: number, sequence: number, random: number, enable: boolean): Promise<void>;
|
||||
|
||||
@@ -135,7 +122,6 @@ export interface BridgeInterface {
|
||||
fetchCustomFace(count?: number): Promise<string[]>;
|
||||
getProfileLike(userId?: number, start?: number, limit?: number): Promise<any>;
|
||||
getUnidirectionalFriendList(): Promise<any>;
|
||||
getGroupAtAllRemain(groupId: number): Promise<any>;
|
||||
|
||||
// ─── Misc ───
|
||||
translateEn2Zh(words: string[]): Promise<any>;
|
||||
|
||||
@@ -31,22 +31,7 @@ import {
|
||||
setFriendAddRequest as setFriendAddRequest_,
|
||||
setFriendRemark as setFriendRemark_,
|
||||
} from './actions/friend';
|
||||
import {
|
||||
getGroupAtAllRemain as getGroupAtAllRemain_,
|
||||
kickGroupMember as kickGroupMember_,
|
||||
kickGroupMembers as kickGroupMembers_,
|
||||
leaveGroup as leaveGroup_,
|
||||
muteGroupAll as muteGroupAll_,
|
||||
muteGroupMember as muteGroupMember_,
|
||||
setGroupAddOption as setGroupAddOption_,
|
||||
setGroupAddRequest as setGroupAddRequest_,
|
||||
setGroupAdmin as setGroupAdmin_,
|
||||
setGroupCard as setGroupCard_,
|
||||
setGroupName as setGroupName_,
|
||||
setGroupRemark as setGroupRemark_,
|
||||
setGroupSearch as setGroupSearch_,
|
||||
setGroupSpecialTitle as setGroupSpecialTitle_,
|
||||
} from './actions/group-admin';
|
||||
// actions/group-admin.ts removed — moved to `apis/group-admin.ts::GroupAdminApi`.
|
||||
import {
|
||||
commentGroupAlbumMedia as commentGroupAlbumMedia_,
|
||||
deleteGroupAlbumMedia as deleteGroupAlbumMedia_,
|
||||
@@ -354,19 +339,11 @@ export class Bridge implements BridgeInterface {
|
||||
// fetchUserProfile / fetchGroupRequests / fetchDownloadRKeys
|
||||
// moved to apis.contacts (see apis/contacts.ts::ContactsApi).
|
||||
|
||||
// --- Delegated: Admin / action methods ---
|
||||
|
||||
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); }
|
||||
async setGroupName(groupId: number, name: string): Promise<void> { return setGroupName_(this, groupId, name); }
|
||||
async setGroupSpecialTitle(groupId: number, userId: number, title: string): Promise<void> { return setGroupSpecialTitle_(this, groupId, userId, title); }
|
||||
// --- Delegated: action methods ---
|
||||
//
|
||||
// GroupAdmin methods (mute/kick/admin/card/name/title/leave/
|
||||
// add-option/search/add-request/remark/at-all-remain) moved to
|
||||
// apis.groupAdmin (apis/group-admin.ts::GroupAdminApi).
|
||||
async setFriendAddRequest(uidOrFlag: string, approve: boolean): Promise<void> { return setFriendAddRequest_(this, uidOrFlag, approve); }
|
||||
async deleteFriend(userId: number, block = false): Promise<void> { return deleteFriend_(this, userId, block); }
|
||||
async uploadGroupFile(groupId: number, file: string, name = '', folderId = '/', uploadFile = true): Promise<{ fileId: string | null }> {
|
||||
@@ -392,14 +369,12 @@ export class Bridge implements BridgeInterface {
|
||||
async createGroupFileFolder(groupId: number, name: string, parentId = '/'): Promise<void> { return createGroupFileFolder_(this, groupId, name, parentId); }
|
||||
async deleteGroupFileFolder(groupId: number, folderId: string): Promise<void> { return deleteGroupFileFolder_(this, groupId, folderId); }
|
||||
async renameGroupFileFolder(groupId: number, folderId: string, newFolderName: string): Promise<void> { return renameGroupFileFolder_(this, groupId, folderId, newFolderName); }
|
||||
async setGroupAddRequest(groupId: number, sequence: number, eventType: number, approve: boolean, reason = '', filtered = false): Promise<void> { return setGroupAddRequest_(this, groupId, sequence, eventType, approve, reason, filtered); }
|
||||
async sendPoke(isGroup: boolean, peerUin: number, targetUin?: number): Promise<void> { return sendPoke_(this, isGroup, peerUin, targetUin); }
|
||||
async sendLike(userId: number, count: number): Promise<void> { return sendLike_(this, userId, count); }
|
||||
async setGroupEssence(groupId: number, sequence: number, random: number, enable: boolean): Promise<void> { return setGroupEssence_(this, groupId, sequence, random, enable); }
|
||||
async setGroupReaction(groupId: number, sequence: number, code: string, isSet: boolean): Promise<void> { return setGroupReaction_(this, groupId, sequence, code, isSet); }
|
||||
// recall* / markRead* moved to apis/message.ts::MessageApi.
|
||||
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);
|
||||
}
|
||||
@@ -450,9 +425,6 @@ export class Bridge implements BridgeInterface {
|
||||
|
||||
async fetchGroupFileCount(groupId: number): Promise<{ fileCount: number; maxCount: number }> { return fetchGroupFileCount_(this, groupId); }
|
||||
|
||||
async getGroupAtAllRemain(groupId: number) {
|
||||
return getGroupAtAllRemain_(this, groupId);
|
||||
}
|
||||
// extend
|
||||
async setOnlineStatus(status: number, extStatus: number = 0, batteryStatus: number = 100): Promise<void> {
|
||||
return setOnlineStatus_(this, status, extStatus, batteryStatus);
|
||||
|
||||
@@ -550,7 +550,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (params.remark === undefined) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'remark is required (pass an empty string to clear)');
|
||||
}
|
||||
await ctx.bridge.setGroupRemark(groupId, asString(params.remark));
|
||||
await ctx.bridge.apis.groupAdmin.setRemark(groupId, asString(params.remark));
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -888,7 +888,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const data = await ctx.bridge.getGroupAtAllRemain(groupId);
|
||||
const data = await ctx.bridge.apis.groupAdmin.getAtAllRemain(groupId);
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
|
||||
@@ -42,14 +42,14 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const addType = asNumber(params.add_type);
|
||||
if (!groupId || addType === undefined) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and add_type are required');
|
||||
await ctx.bridge.setGroupAddOption(groupId, addType);
|
||||
await ctx.bridge.apis.groupAdmin.setAddOption(groupId, addType);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
h.registerAction('set_group_search', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
await ctx.bridge.setGroupSearch(groupId);
|
||||
await ctx.bridge.apis.groupAdmin.setSearch(groupId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -58,7 +58,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const enable = asBoolean(params.enable, true);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.bridge.setGroupAdmin(groupId, userId, enable);
|
||||
await ctx.bridge.apis.groupAdmin.setAdmin(groupId, userId, enable);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -67,7 +67,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const card = asString(params.card);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.bridge.setGroupCard(groupId, userId, card);
|
||||
await ctx.bridge.apis.groupAdmin.setCard(groupId, userId, card);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const name = asString(params.group_name);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
await ctx.bridge.setGroupName(groupId, name);
|
||||
await ctx.bridge.apis.groupAdmin.setName(groupId, name);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const title = asString(params.special_title);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.bridge.setGroupSpecialTitle(groupId, userId, title);
|
||||
await ctx.bridge.apis.groupAdmin.setSpecialTitle(groupId, userId, title);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
|
||||
@@ -112,11 +112,11 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
getStrangerInfo: (userId) => getStrangerInfo(bridge, userId),
|
||||
|
||||
// Group admin — names translate to OneBot vocabulary.
|
||||
setGroupKick: (groupId, userId, reject) => bridge.kickGroupMember(groupId, userId, reject),
|
||||
setGroupKickMembers: (groupId, userIds, reject) => bridge.kickGroupMembers(groupId, userIds, reject),
|
||||
setGroupBan: (groupId, userId, duration) => bridge.muteGroupMember(groupId, userId, duration),
|
||||
setGroupWholeBan: (groupId, enable) => bridge.muteGroupAll(groupId, enable),
|
||||
setGroupLeave: (groupId) => bridge.leaveGroup(groupId),
|
||||
setGroupKick: (groupId, userId, reject) => bridge.apis.groupAdmin.kickMember(groupId, userId, reject),
|
||||
setGroupKickMembers: (groupId, userIds, reject) => bridge.apis.groupAdmin.kickMembers(groupId, userIds, reject),
|
||||
setGroupBan: (groupId, userId, duration) => bridge.apis.groupAdmin.muteMember(groupId, userId, duration),
|
||||
setGroupWholeBan: (groupId, enable) => bridge.apis.groupAdmin.muteAll(groupId, enable),
|
||||
setGroupLeave: (groupId) => bridge.apis.groupAdmin.leave(groupId),
|
||||
|
||||
// Group file — fileId field extraction + defaults.
|
||||
uploadGroupFile: async (groupId, file, name, folderId, uploadFile) => {
|
||||
@@ -164,7 +164,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
handleDeleteFriend: (userId, block) => bridge.deleteFriend(userId, !!block),
|
||||
forceFetchClientKey: () => bridge.forceFetchClientKey(),
|
||||
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
||||
setGroupRemark: (groupId, remark) => bridge.setGroupRemark(groupId, remark),
|
||||
setGroupRemark: (groupId, remark) => bridge.apis.groupAdmin.setRemark(groupId, remark),
|
||||
setGroupAvatar: (groupId, source) => bridge.setGroupAvatar(groupId, source),
|
||||
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function handleGroupAddRequest(
|
||||
throw new Error('matching group request not found');
|
||||
}
|
||||
|
||||
await bridge.setGroupAddRequest(
|
||||
await bridge.apis.groupAdmin.setAddRequest(
|
||||
groupId,
|
||||
matching.sequence,
|
||||
matching.eventType,
|
||||
|
||||
@@ -21,7 +21,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as admin from '../../src/bridge/actions/group-admin';
|
||||
import { GroupAdminApi } from '../../src/bridge/apis/group-admin';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
describe('actions/group-admin', () => {
|
||||
@@ -33,7 +33,7 @@ describe('actions/group-admin', () => {
|
||||
|
||||
it('muteGroupMember resolves UID and dispatches 0x1253_1', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.muteGroupMember(bridge as any, 12345, 67890, 600);
|
||||
await new GroupAdminApi(bridge as any).muteMember(12345, 67890, 600);
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
|
||||
expect(oidb.runOidb).toHaveBeenCalledOnce();
|
||||
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
||||
@@ -50,13 +50,13 @@ describe('actions/group-admin', () => {
|
||||
|
||||
it('muteGroupAll flips the muteState flag based on enable', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.muteGroupAll(bridge as any, 12345, true);
|
||||
await new GroupAdminApi(bridge as any).muteAll(12345, true);
|
||||
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2]).toMatchObject({
|
||||
groupUin: 12345,
|
||||
muteState: { state: 0xFFFFFFFF },
|
||||
});
|
||||
|
||||
await admin.muteGroupAll(bridge as any, 12345, false);
|
||||
await new GroupAdminApi(bridge as any).muteAll(12345, false);
|
||||
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[1]![2]).toMatchObject({
|
||||
muteState: { state: 0 },
|
||||
});
|
||||
@@ -64,7 +64,7 @@ describe('actions/group-admin', () => {
|
||||
|
||||
it('kickGroupMember resolves UID per-group and forwards reject + reason', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.kickGroupMember(bridge as any, 12345, 67890, true, 'bad behaviour');
|
||||
await new GroupAdminApi(bridge as any).kickMember(12345, 67890, true, 'bad behaviour');
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
|
||||
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2]).toMatchObject({
|
||||
groupUin: 12345,
|
||||
@@ -80,7 +80,7 @@ describe('actions/group-admin', () => {
|
||||
.mockResolvedValueOnce('uid-a')
|
||||
.mockResolvedValueOnce('uid-b');
|
||||
|
||||
await admin.kickGroupMembers(bridge as any, 12345, [11, 22], false);
|
||||
await new GroupAdminApi(bridge as any).kickMembers(12345, [11, 22], false);
|
||||
expect(bridge.resolveUserUid).toHaveBeenCalledTimes(2);
|
||||
const payload: any = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
||||
expect(payload.targetUids).toEqual(['uid-a', 'uid-b']);
|
||||
@@ -89,7 +89,7 @@ describe('actions/group-admin', () => {
|
||||
|
||||
it('leaveGroup sends 0x1097_1 with the groupUin', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.leaveGroup(bridge as any, 12345);
|
||||
await new GroupAdminApi(bridge as any).leave(12345);
|
||||
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x1097_1');
|
||||
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2]).toMatchObject({ groupUin: 12345 });
|
||||
@@ -97,7 +97,7 @@ describe('actions/group-admin', () => {
|
||||
|
||||
it('setGroupAdmin resolves UID and sends 0x1096_1', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.setGroupAdmin(bridge as any, 12345, 67890, true);
|
||||
await new GroupAdminApi(bridge as any).setAdmin(12345, 67890, true);
|
||||
expect(vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2]).toMatchObject({
|
||||
groupUin: 12345, uid: 'resolved-uid', isAdmin: true,
|
||||
});
|
||||
@@ -105,12 +105,12 @@ describe('actions/group-admin', () => {
|
||||
|
||||
it('setGroupCard / setGroupName / setGroupSpecialTitle / setGroupRemark / setGroupAddOption / setGroupSearch dispatch the right command', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.setGroupCard(bridge as any, 1, 2, 'newCard');
|
||||
await admin.setGroupName(bridge as any, 1, 'newName');
|
||||
await admin.setGroupSpecialTitle(bridge as any, 1, 2, 'newTitle');
|
||||
await admin.setGroupRemark(bridge as any, 1, 'newRemark');
|
||||
await admin.setGroupAddOption(bridge as any, 1, 2);
|
||||
await admin.setGroupSearch(bridge as any, 1);
|
||||
await new GroupAdminApi(bridge as any).setCard(1, 2, 'newCard');
|
||||
await new GroupAdminApi(bridge as any).setName(1, 'newName');
|
||||
await new GroupAdminApi(bridge as any).setSpecialTitle(1, 2, 'newTitle');
|
||||
await new GroupAdminApi(bridge as any).setRemark(1, 'newRemark');
|
||||
await new GroupAdminApi(bridge as any).setAddOption(1, 2);
|
||||
await new GroupAdminApi(bridge as any).setSearch(1);
|
||||
|
||||
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(call => call[1]);
|
||||
expect(cmds).toEqual([
|
||||
@@ -125,8 +125,8 @@ describe('actions/group-admin', () => {
|
||||
|
||||
it('setGroupAddRequest picks _1 / _2 based on filtered flag', async () => {
|
||||
const bridge = mockBridge();
|
||||
await admin.setGroupAddRequest(bridge as any, 12345, 5, 1, true, 'ok', false);
|
||||
await admin.setGroupAddRequest(bridge as any, 12345, 5, 1, false, 'no', true);
|
||||
await new GroupAdminApi(bridge as any).setAddRequest(12345, 5, 1, true, 'ok', false);
|
||||
await new GroupAdminApi(bridge as any).setAddRequest(12345, 5, 1, false, 'no', true);
|
||||
|
||||
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(call => call[1]);
|
||||
expect(cmds).toEqual([
|
||||
@@ -149,7 +149,7 @@ describe('actions/group-admin', () => {
|
||||
body: { canAtAll: true, groupRemain: 12, uinRemain: 5 } as any,
|
||||
}),
|
||||
);
|
||||
const out = await admin.getGroupAtAllRemain(bridge as any, 12345);
|
||||
const out = await new GroupAdminApi(bridge as any).getAtAllRemain(12345);
|
||||
expect(out).toEqual({
|
||||
can_at_all: true,
|
||||
remain_at_all_count_for_group: 12,
|
||||
@@ -164,6 +164,6 @@ describe('actions/group-admin', () => {
|
||||
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
||||
protobuf_encode<OidbBase<Oidb0x8a7Resp>>({}),
|
||||
);
|
||||
await expect(admin.getGroupAtAllRemain(bridge as any, 12345)).rejects.toThrow(/empty/);
|
||||
await expect(new GroupAdminApi(bridge as any).getAtAllRemain(12345)).rejects.toThrow(/empty/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,32 +52,32 @@ function fakeRequest(overrides: Partial<GroupRequestInfo> = {}): GroupRequestInf
|
||||
|
||||
describe('onebot/modules/request-actions / handleGroupAddRequest', () => {
|
||||
it('matches add requests by groupId and targetUid', async () => {
|
||||
const setGroupAddRequest = vi.fn(async () => {});
|
||||
const setAddRequest = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupRequests: vi.fn(async () => [
|
||||
fakeRequest({ groupId: 999, targetUid: 'u_t', sequence: 42, eventType: 7, filtered: false }),
|
||||
]),
|
||||
setGroupAddRequest: setGroupAddRequest as any,
|
||||
apis: { groupAdmin: { setAddRequest } } as any,
|
||||
});
|
||||
|
||||
await handleGroupAddRequest(bridge, 'add:999:u_t', true, 'ok');
|
||||
|
||||
expect(setGroupAddRequest).toHaveBeenCalledOnce();
|
||||
expect(setGroupAddRequest).toHaveBeenCalledWith(999, 42, 7, true, 'ok', false);
|
||||
expect(setAddRequest).toHaveBeenCalledOnce();
|
||||
expect(setAddRequest).toHaveBeenCalledWith(999, 42, 7, true, 'ok', false);
|
||||
});
|
||||
|
||||
it('matches invite requests by groupId and invitorUid', async () => {
|
||||
const setGroupAddRequest = vi.fn(async () => {});
|
||||
const setAddRequest = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupRequests: vi.fn(async () => [
|
||||
fakeRequest({ groupId: 999, invitorUid: 'u_i', sequence: 97, eventType: 8, filtered: false }),
|
||||
]),
|
||||
setGroupAddRequest: setGroupAddRequest as any,
|
||||
apis: { groupAdmin: { setAddRequest } } as any,
|
||||
});
|
||||
|
||||
await handleGroupAddRequest(bridge, 'invite:999:u_i', false, 'no');
|
||||
|
||||
expect(setGroupAddRequest).toHaveBeenCalledOnce();
|
||||
expect(setGroupAddRequest).toHaveBeenCalledWith(999, 97, 8, false, 'no', false);
|
||||
expect(setAddRequest).toHaveBeenCalledOnce();
|
||||
expect(setAddRequest).toHaveBeenCalledWith(999, 97, 8, false, 'no', false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user