Adding !fetch command.
Beautified code. Should have branched for that, but alas.
This commit is contained in:
parent
92da7fb1e8
commit
dfc3985f9d
75
index.js
75
index.js
|
@ -9,7 +9,10 @@ const xmpp = require('simple-xmpp');
|
|||
|
||||
var db = new sqlite3.Database('nip26.db');
|
||||
|
||||
let { bech32, bech32m } = require('bech32');
|
||||
let {
|
||||
bech32,
|
||||
bech32m
|
||||
} = require('bech32');
|
||||
let letsCID;
|
||||
let signedEvent;
|
||||
|
||||
|
@ -29,22 +32,65 @@ if (fs.existsSync('./config.ini')) {
|
|||
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');
|
||||
debug();
|
||||
}
|
||||
else if (message === "!auth"){
|
||||
xmpp.send(from,"reauth (nip-26)");
|
||||
} else if (message === "!auth") {
|
||||
xmpp.send(from, "reauth (nip-26)");
|
||||
|
||||
const now = new Date();
|
||||
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.finalize();
|
||||
debug();
|
||||
}
|
||||
else {
|
||||
async function main() {
|
||||
} else {
|
||||
async function newPost() {
|
||||
const relay = nostr.relayInit(config.relays.write, WebSocket);
|
||||
relay.on('connect', () => {
|
||||
console.log(`connected to ${relay.url}`);
|
||||
|
@ -62,19 +108,16 @@ if (fs.existsSync('./config.ini')) {
|
|||
tags: [],
|
||||
content: message,
|
||||
};
|
||||
|
||||
const signedEvent = nostr.finishEvent(event, sk);
|
||||
letsCID = signedEvent.id;
|
||||
showSID(letsCID,pk);
|
||||
showSID(letsCID, pk);
|
||||
await relay.publish(signedEvent);
|
||||
relay.close();
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
newPost().catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
async function showSID(letsCID,pk) {
|
||||
async function showSID(letsCID, pk) {
|
||||
console.log(letsCID);
|
||||
console.log(pk);
|
||||
const event = {
|
||||
|
@ -99,7 +142,7 @@ if (fs.existsSync('./config.ini')) {
|
|||
host: config.xmpp.host,
|
||||
port: 5222
|
||||
});
|
||||
process.on('SIGINT', function() {
|
||||
process.on('SIGINT', function () {
|
||||
console.log("SigInt receieved. Shutdown inevitable!")
|
||||
process.exit();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user