fix(onebot): approve pending group join requests that were rejected as gone

Closes #380.

An empty reject reason and a stale request type could make the server treat a still-pending join as already handled.
This commit is contained in:
DrSmoothl committed 2026-08-17 18:40:08 +08:00
1 parent 618dd52f46
commit aec0c781b3
11 files changed
+136 -45

No files matched your search

@@ -20,21 +20,30 @@ export namespace SetAddRequest {
approve: boolean;
reason?: string;
filtered?: boolean;
operateTransInfo?: Uint8Array;
}
export type Deps = OidbSender;
export const resolveSubCommand = (p: Params): number => p.filtered ? 2 : 1;
export const serialize = (_ctx: Deps, p: Params): OidbGroupRequestAction => ({
accept: p.approve ? 1 : 2,
body: {
sequence: BigInt(p.sequence),
eventType: p.eventType,
groupUin: p.groupId,
message: p.reason ?? '',
},
});
export const serialize = (_ctx: Deps, p: Params): OidbGroupRequestAction => {
const reason = p.reason ?? '';
return {
accept: p.approve ? 1 : 2,
body: {
sequence: BigInt(p.sequence),
eventType: p.eventType,
groupUin: p.groupId,
// Native operate always writes field 4. An omitted empty string is
// rejected; a present space is the native empty-reason form.
message: reason.length > 0 ? reason : ' ',
...(p.operateTransInfo && p.operateTransInfo.length > 0
? { operateTransInfo: p.operateTransInfo }
: {}),
},
};
};
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
+1
View File
@@ -81,6 +81,7 @@ export interface GroupRequestInfo {
eventType: number;
comment: string;
filtered: boolean;
operateTransInfo?: Uint8Array;
}
/** Approval tuple required by OIDB 0x10C8. The OneBot flag is opaque to
@@ -41,12 +41,25 @@ describe('SetAddRequest namespace', () => {
expect(env.body?.accept).toBe(2);
});
it('defaults reason to empty string', async () => {
it('writes a space when the reason is empty so field 4 stays present', async () => {
const deps = makeDeps();
await SetAddRequest.invoke(deps, { groupId: 1, sequence: 1, eventType: 0, approve: true });
await SetAddRequest.invoke(deps, { groupId: 1, sequence: 1, eventType: 1, approve: true });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbGroupRequestAction>>(bytes);
// proto3 empty string omitted on the wire.
expect(env.body?.body?.message ?? '').toBe('');
expect(env.body?.body?.message).toBe(' ');
const arr = Array.from(bytes);
const hasMessageField = arr.some((_, i) => arr[i] === 0x22 && arr[i + 1] === 0x01 && arr[i + 2] === 0x20);
expect(hasMessageField).toBe(true);
});
it('forwards operateTransInfo as body field 7', async () => {
const deps = makeDeps();
const operateTransInfo = Uint8Array.from([0x01, 0x02, 0x03]);
await SetAddRequest.invoke(deps, {
groupId: 1, sequence: 1, eventType: 1, approve: true, reason: 'ok', operateTransInfo,
});
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbGroupRequestAction>>(bytes);
expect(env.body?.body?.operateTransInfo).toEqual(operateTransInfo);
});
});