diff --git a/scripts/nostr-pull.ts b/scripts/nostr-pull.ts index c3cbb67b..1a236f8f 100644 --- a/scripts/nostr-pull.ts +++ b/scripts/nostr-pull.ts @@ -1,5 +1,6 @@ /** - * Script to import a user/list of users into Ditto given their npub/pubkey by looking them up on a list of relays. + * Script to import a user/list of users into Ditto given their npub/pubkey + * by looking them up on a list of relays. */ import { NostrEvent, NRelay1, NSchema } from '@nostrify/nostrify'; @@ -26,13 +27,13 @@ const importUsers = async ( const profiles: Record> = {}; // Kind 1s. const notes = new Set(); - const { profilesOnly = false } = opts || {}; await Promise.all(relays.map(async (relay) => { if (!relay.startsWith('wss://')) console.error(`Invalid relay url ${relay}`); const conn = new NRelay1(relay); const matched = await conn.query([{ kinds: [0, 3], authors, limit: 1000 }]); + if (!profilesOnly) { matched.push( ...await conn.query( @@ -65,6 +66,20 @@ const importUsers = async ( for (const kind in profile) { await doEvent(profile[kind]); } + + let name = user; + // kind 0, not first idx + const event = profile[0]; + if (event) { + // if event exists, print name + const parsed = JSON.parse(event.content); + name = parsed.nip05 || parsed.name || name; + } + if (NSchema.id().safeParse(name).success) { + // if no kind 0 found and this is a pubkey, encode as npub + name = nip19.npubEncode(name); + } + console.info(`Imported user ${name}${profilesOnly ? "'s profile" : ''}.`); } }; @@ -85,6 +100,7 @@ if (import.meta.main) { if (optionsEnd) { console.error('Option encountered after end of options section.'); showUsage(); + Deno.exit(1); } switch (arg) { case '-p':