40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
// scuttlebot.js
|
|
|
|
const ssbClient = require('ssb-client');
|
|
const ssbKeys = require('ssb-keys');
|
|
const pull = require('pull-stream');
|
|
|
|
const keys = ssbKeys.loadOrCreateSync('~/.ssb/secret');
|
|
|
|
ssbClient(keys, (err, sbot) => {
|
|
if (err) {
|
|
console.error(JSON.stringify({ "error": "Failed to connect to the Scuttlebot server. Is it running?" }));
|
|
console.error(err);
|
|
process.exit(1);
|
|
}
|
|
|
|
const authors = new Set();
|
|
|
|
pull(
|
|
sbot.messagesByType("contact"),
|
|
pull.drain((msg) => {
|
|
authors.add(msg.value.author);
|
|
}, (err) => {
|
|
if (err) {
|
|
console.error(JSON.stringify({ "error": "Failed to retrieve messages." }));
|
|
console.error(err);
|
|
process.exit(1);
|
|
}
|
|
|
|
const feeds = Array.from(authors).map(author => { return { id: author } });
|
|
console.log(JSON.stringify(feeds));
|
|
try {
|
|
sbot.close(() => {});
|
|
} catch(err) {
|
|
console.error("Error closing SSB server connection: ", err);
|
|
}
|
|
})
|
|
);
|
|
});
|
|
|