refactor(core): drop NtqqHandler shim, route packets directly to BridgeManager
NtqqHandler was a 54-line "shallow module": half of its public surface
(registerCmd by service-cmd) had zero callers — cmdHandlers was a Map
that nothing ever wrote to. The remaining half (registerCmdAll) had
exactly one subscriber: BridgeManager.bind() wiring its private
onPacket. So NtqqHandler was, in effect, a one-listener event emitter
plus a five-line field-rename from QqHookPacket to PacketInfo.
The deletion test concentrates the change rather than scattering it:
- HookSession.handlePacket inlines the field rename and pushes
straight into a PacketSink dependency (PacketInfo => void).
HookSession's ctor now takes `onPacket?: PacketSink` instead of
`ntqq?: NtqqHandler` — the new shape is exactly what tests want
(a vi.fn() spy with no event-emitter scaffolding).
- HookManager's `ntqq: NtqqHandler` constructor dep becomes
`onPacket?: PacketSink`, defaulting to `bridgeManager.onPacket` so
the common-case wiring stays one line at the call site.
- BridgeManager.bind(ntqq) is deleted; BridgeManager.onPacket becomes
public (it was always the real entry point). The file header
comment now describes onPacket as the single packet entry rather
than "wires NtqqHandler".
- index.ts shrinks: no `new NtqqHandler()` and no `bridgeManager.bind`.
`new HookManager({ bridgeManager })` covers both wires.
- packages/core/src/protocol/ntqq-handler.ts deleted.
Behavior preserved: same field rename (Buffer.from(packet.body) for
the body copy that QqHookClient already does, kept to match
byte-for-byte), same login + real-uin filter, same logging scope is
gone (`createLogger('NTQQ')` had no remaining call sites). PacketSink
type alias added to protocol/types.ts so the dep type stays readable
across HookSession + HookManager.
Adds 5 unit tests for the inlined packet path that the deleted module
never had: PacketInfo shape, session-uin fallback when packet.uin is
empty, pre-login drop, non-real-uin drop, and a no-sink no-op.
184 tests pass (was 179); only failing suite is the pre-existing
macOS-arm64 missing websocket native addon, unrelated.
This commit is contained in:
1 parent
4fc52578a5
commit
ef4a321175
7 files changed
+154
-80
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import { NtqqHandler } from './protocol/ntqq-handler';
|
||||
import { BridgeManager } from './bridge/manager';
|
||||
import { OneBotManager } from './onebot/manager';
|
||||
import { loadRuntimeConfig } from './common/runtime';
|
||||
@@ -11,13 +10,13 @@ const log = createLogger('App');
|
||||
async function main() {
|
||||
log.info('SnowLuma starting');
|
||||
|
||||
const ntqq = new NtqqHandler();
|
||||
const bridgeManager = new BridgeManager();
|
||||
const oneBotManager = new OneBotManager();
|
||||
const hookManager = new HookManager({ ntqq, bridgeManager });
|
||||
// HookManager defaults its packet sink to bridgeManager.onPacket, so
|
||||
// every parsed hook packet reaches the per-UIN bridge dispatcher with
|
||||
// no intermediate layer.
|
||||
const hookManager = new HookManager({ bridgeManager });
|
||||
|
||||
// Bind bridge manager to NTQQ handler (receives all parsed packets)
|
||||
bridgeManager.bind(ntqq);
|
||||
oneBotManager.bind(bridgeManager);
|
||||
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user