fix(onebot): make the event pipeline tables type-check
A handler shared by several event kinds now types as one kind at a time. The converter table still records which kinds are not converted, so the compile-time check for dropped converted kinds works.
This commit is contained in:
2 files changed
+10
-3
No files matched your search
@@ -73,7 +73,7 @@ type ConverterFor<K extends QQEventVariant['kind']> =
|
||||
*/
|
||||
export type ConverterRegistry = { [K in QQEventVariant['kind']]: ConverterFor<K> | null };
|
||||
|
||||
export const CONVERTERS: ConverterRegistry = {
|
||||
export const CONVERTERS = {
|
||||
// Messages.
|
||||
friend_message: convertFriendMessage,
|
||||
group_message: convertGroupMessage,
|
||||
@@ -107,7 +107,7 @@ export const CONVERTERS: ConverterRegistry = {
|
||||
online_devices_changed: null,
|
||||
// Internal-only identity synchronization from another QQ client.
|
||||
friend_remark_changed: null,
|
||||
};
|
||||
} satisfies ConverterRegistry;
|
||||
|
||||
export async function convertEvent(
|
||||
ctx: ConverterContext,
|
||||
|
||||
@@ -424,7 +424,14 @@ function handlePttTransResult(
|
||||
traceEventTerminal(log, event.kind, state, 'internal', 'waiter_notified');
|
||||
}
|
||||
|
||||
const convertOnly: PipelineHandler<EventKind> = convertAndDispatch;
|
||||
function convertOnly<K extends EventKind>(
|
||||
ctx: OneBotInstanceContext,
|
||||
log: Logger,
|
||||
event: Extract<QQEventVariant, { kind: K }>,
|
||||
state: EventTraceState,
|
||||
): Promise<void> {
|
||||
return convertAndDispatch(ctx, log, event, state);
|
||||
}
|
||||
|
||||
const EVENT_PIPELINE = {
|
||||
friend_message: { handle: handleFriendMessage },
|
||||
|
||||
Reference in new issue
Block a user