diff --git a/src/pipeline.ts b/src/pipeline.ts index ead0044..730e333 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -37,6 +37,7 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise { + if (event.kind !== 5951) return; + const signer = new AdminSigner(); + + const exists = (await eventsDB.count( + [{ kinds: [30361], authors: [Conf.pubkey], '#d': [event.pubkey], limit: 1 }], + )).count > 0; + + if (exists) { + const feedback = await signer.signEvent({ + kind: 7000, + content: '', + tags: [ + ['status', 'error', 'User already exists'], + ['e', event.id], + ['p', event.pubkey], + ], + created_at: nostrNow(), + }); + return handleEvent(feedback, AbortSignal.timeout(1000)); + } + + const user = await signer.signEvent({ + kind: 30361, + tags: [ + ['d', event.pubkey], + ], + content: '', + created_at: nostrNow(), + }); + + const resp = await signer.signEvent({ + kind: 6951, + content: Conf.relay, + tags: [ + ['request', JSON.stringify(event)], + ['i', Conf.relay, 'text'], + ['p', event.pubkey], + ['e', event.id], + ], + created_at: nostrNow(), + }); + + await Promise.all([ + handleEvent(user, AbortSignal.timeout(1000)), + handleEvent(resp, AbortSignal.timeout(1000)), + ]); +} + /** Emit Nostr Wallet Connect event from zaps so users may pay. */ async function payZap(event: DittoEvent, signal: AbortSignal) { if (event.kind !== 9734 || !event.user) return;