OneBot used to depend on the concrete Bridge class — 778 lines, ~99 public methods including PID management, raw packet dispatch, and cmd handler registration that no external consumer should touch. Add an explicit BridgeInterface (bridge/bridge-interface.ts) enumerating only the surface OneBot actually reads (verified by grepping every bridge.* access in onebot/), and have Bridge `implements BridgeInterface` so the compiler enforces alignment. Net effect at runtime: zero — Bridge's methods, fields, and bodies are unchanged; the interface is a TypeScript-only declaration. Net effect for typing: the OneBot package (instance, instance-context, instance-rkey, manager, media-url-resolver, and the modules under onebot/modules/) now imports `BridgeInterface` instead of `Bridge`, so tests / fakes can satisfy the interface without subclassing or pulling in the SQLite/native bits. In-tree bridge actions (actions/*, bridge-contacts, highway) keep their concrete `Bridge` typing — they legitimately need sendRawPacket and other low-level entry points that intentionally stay off the interface.
30 lines
854 B
TypeScript
30 lines
854 B
TypeScript
import type { BridgeInterface } from '../../bridge/bridge-interface';
|
|
|
|
export async function handleGroupAddRequest(
|
|
bridge: BridgeInterface,
|
|
flag: string,
|
|
approve: boolean,
|
|
reason: string,
|
|
): Promise<void> {
|
|
// flag format: "add:groupId:uid" or "invite:groupId:uid" (from event-converter)
|
|
const parts = flag.split(':');
|
|
if (parts.length < 3) throw new Error('invalid group request flag');
|
|
const groupId = parseInt(parts[1], 10);
|
|
if (!groupId) throw new Error('invalid group_id in flag');
|
|
|
|
const requests = await bridge.fetchGroupRequests();
|
|
const matching = requests.find(r => r.groupId === groupId);
|
|
if (!matching) {
|
|
throw new Error('matching group request not found');
|
|
}
|
|
|
|
await bridge.setGroupAddRequest(
|
|
groupId,
|
|
matching.sequence,
|
|
matching.eventType,
|
|
approve,
|
|
reason,
|
|
matching.filtered,
|
|
);
|
|
}
|