npubweb/run.ts

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-01-11 19:08:10 +00:00
import NDK, {NDKFilter} from 'npm:@nostr-dev-kit/ndk';
const ndk = new NDK({
explicitRelayUrls: [
//"ws://127.0.0.1", // localhost access is be whitelist
"wss://bitcoiner.social",
"wss://offchain.pub",
"wss://relay.snort.social",
"wss://nos.lol",
],
});
await ndk.connect();
function getName(profile: NDKUserProfile): string {
if (profile.nip05) {
return profile.nip05;
} else if (profile.name) {
return profile.name;
} else if (profile.username) {
return profile.username;
} else {
return profile.npub;
}
}
const premiumPubkeysFile = await Deno.readTextFile('pubkeys.premium.json');
const premiumPubkeys: string[] = JSON.parse(premiumPubkeysFile);
for (const subscriberPubkey of premiumPubkeys) {
const subscriber = ndk.getUser({
pubkey: subscriberPubkey,
});
console.log("Subscriber:",subscriber.npub)
await subscriber.fetchProfile();
//const subscriberName = getName(subscriber.profile);
//console.log("Subscriber Name:",subscriberName)
//const follows = await subscriber.follows();
//console.log(`${subscriberName} follows ${follows.size}`);
}
for (const foaf of follows) {
console.log(foaf.pubkey);
}
const test = ndk.getUser({
pubkey: "69a0a0910b49a1dbfbc4e4f10df22b5806af5403a228267638f2e908c968228d",
});
await test.fetchProfile();
getName(test.profile);