npubweb/scratchpad.ts

49 lines
1.6 KiB
TypeScript

//const filter: NDKFilter = { kinds: [3], authors: ["69a0a0910b49a1dbfbc4e4f10df22b5806af5403a228267638f2e908c968228d"] };
//const event = await ndk.fetchEvent(filter);
// https://ndk.fyi/docs/classes/NDKEvent.html
//console.log(event.rawEvent());
//console.log(event?.content);
//console.log(event?.created_at);
//console.log(event?.tags.length);
//event.rawEvent().tags.forEach((tag) => {
// if (tag[0] === "p"){
// console.log(tag[1])
// }
//});
async function insertFoaf(subscriberPubkey: string, foafPubkey: string) {
db.query("INSERT INTO foaf (foaf_pubkey, subscriber_pubkey) VALUES (?, ?)", [foafPubkey, subscriberPubkey]);
}
const filter: NDKFilter = { kinds: [3], authors: [subscriberPubkey] };
const follows = await ndk.fetchEvent(filter);
follows.tags.forEach((tag) => {
if (tag[0] === "p") {
const foafPubkey = tag[1]; // Extract the FOAF pubkey
console.log(foafPubkey); // Log the FOAF pubkey
// Insert the FOAF pubkey into the database
insertFoaf(subscriber_pubkey, foafPubkey);
}
});
// npub1dxs2pygtfxsah77yuncsmu3ttqr274qr5g5zva3c7t5s3jtgy2xszsn4st
// hex: 69a0a0910b49a1dbfbc4e4f10df22b5806af5403a228267638f2e908c968228d
const blee = ndk.getUser({
npub: "npub1dxs2pygtfxsah77yuncsmu3ttqr274qr5g5zva3c7t5s3jtgy2xszsn4st",
});
// https://ndk.fyi/docs/classes/NDKUser.html#follows
const follows = await blee.follows();
console.log("Number of follows:", follows.size);
for (const foaf of follows) {
console.log(foaf.pubkey);
}
// Will return only the first event
event = await ndk.fetchEvent(filter);