Adding !fetch command. #3
67
index.js
67
index.js
|
@ -9,7 +9,10 @@ const xmpp = require('simple-xmpp');
|
||||||
|
|
||||||
var db = new sqlite3.Database('nip26.db');
|
var db = new sqlite3.Database('nip26.db');
|
||||||
|
|
||||||
let { bech32, bech32m } = require('bech32');
|
let {
|
||||||
|
bech32,
|
||||||
|
bech32m
|
||||||
|
} = require('bech32');
|
||||||
let letsCID;
|
let letsCID;
|
||||||
let signedEvent;
|
let signedEvent;
|
||||||
|
|
||||||
|
@ -29,22 +32,65 @@ if (fs.existsSync('./config.ini')) {
|
||||||
console.log(from);
|
console.log(from);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (message === '!help') {
|
// Add NIP-05, to get users latest kind 3, and notes.
|
||||||
|
if (message === "!fetch") {
|
||||||
|
xmpp.send(from, "Sure. Please standby...");
|
||||||
|
async function gogoGlobalShoes() {
|
||||||
|
const relay = nostr.relayInit(config.relays.read, WebSocket);
|
||||||
|
relay.on('connect', () => {
|
||||||
|
console.log(`connected to ${relay.url}`);
|
||||||
|
});
|
||||||
|
relay.on('error', () => {
|
||||||
|
console.log(`failed to connect to ${relay.url}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
await relay.connect();
|
||||||
|
|
||||||
|
let sub = relay.sub([{
|
||||||
|
kinds: [1],
|
||||||
|
authors: [pk],
|
||||||
|
limit: 5
|
||||||
|
}, ])
|
||||||
|
sub.on('event', event => {
|
||||||
|
console.log('got event:', event);
|
||||||
|
|
||||||
|
// Check if the event is already an object
|
||||||
|
const conny = typeof event === 'string' ? JSON.parse(event) : event;
|
||||||
|
|
||||||
|
if (conny && conny.content && conny.pubkey && conny.created_at) {
|
||||||
|
const content = conny.content;
|
||||||
|
const author = conny.pubkey;
|
||||||
|
const createdAt = conny.created_at;
|
||||||
|
|
||||||
|
// Use the extracted properties as needed
|
||||||
|
console.log('Content:', content);
|
||||||
|
console.log('Author:', author);
|
||||||
|
console.log('Created At:', createdAt);
|
||||||
|
|
||||||
|
// You can send these properties via XMPP or perform other actions here
|
||||||
|
xmpp.send(from, `\"${content}\", - ${author} @ ${createdAt}`);
|
||||||
|
} else {
|
||||||
|
console.error('Invalid event structure or missing required properties.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
gogoGlobalShoes().catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
} else if (message === '!help') {
|
||||||
xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:nostrsms:commands');
|
xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:nostrsms:commands');
|
||||||
debug();
|
debug();
|
||||||
}
|
} else if (message === "!auth") {
|
||||||
else if (message === "!auth"){
|
|
||||||
xmpp.send(from, "reauth (nip-26)");
|
xmpp.send(from, "reauth (nip-26)");
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const validUntil = now.getTime() + (30 * 24 * 60 * 60 * 1000);
|
const validUntil = now.getTime() + (30 * 24 * 60 * 60 * 1000);
|
||||||
const insertStmt = db.prepare('INSERT INTO users (pnum, pk) VALUES (?, ?)');
|
const insertStmt = db.prepare('INSERT INTO users (pnum, token) VALUES (?, ?)');
|
||||||
insertStmt.run(from.split("@")[0], validUntil);
|
insertStmt.run(from.split("@")[0], validUntil);
|
||||||
insertStmt.finalize();
|
insertStmt.finalize();
|
||||||
debug();
|
debug();
|
||||||
}
|
} else {
|
||||||
else {
|
async function newPost() {
|
||||||
async function main() {
|
|
||||||
const relay = nostr.relayInit(config.relays.write, WebSocket);
|
const relay = nostr.relayInit(config.relays.write, WebSocket);
|
||||||
relay.on('connect', () => {
|
relay.on('connect', () => {
|
||||||
console.log(`connected to ${relay.url}`);
|
console.log(`connected to ${relay.url}`);
|
||||||
|
@ -62,18 +108,15 @@ if (fs.existsSync('./config.ini')) {
|
||||||
tags: [],
|
tags: [],
|
||||||
content: message,
|
content: message,
|
||||||
};
|
};
|
||||||
|
|
||||||
const signedEvent = nostr.finishEvent(event, sk);
|
const signedEvent = nostr.finishEvent(event, sk);
|
||||||
letsCID = signedEvent.id;
|
letsCID = signedEvent.id;
|
||||||
showSID(letsCID, pk);
|
showSID(letsCID, pk);
|
||||||
await relay.publish(signedEvent);
|
await relay.publish(signedEvent);
|
||||||
relay.close();
|
relay.close();
|
||||||
}
|
}
|
||||||
|
newPost().catch((error) => {
|
||||||
main().catch((error) => {
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function showSID(letsCID, pk) {
|
async function showSID(letsCID, pk) {
|
||||||
console.log(letsCID);
|
console.log(letsCID);
|
||||||
console.log(pk);
|
console.log(pk);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user