print name as import acknowledgement

This commit is contained in:
Siddharth Singh 2024-07-02 05:21:16 +05:30
parent d2df6721bd
commit 757e5c9baa
No known key found for this signature in database

View file

@ -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<string, Record<number, NostrEvent>> = {};
// Kind 1s.
const notes = new Set<string>();
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':