Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
b7de29a339 | |||
79bc3ca11c | |||
8fb526ee69 | |||
26fc93aafc | |||
ee0cea8d9f |
65
index.js
65
index.js
|
@ -1,5 +1,4 @@
|
||||||
// initialize required packages
|
// initialize required packages
|
||||||
const sqlite3 = require('sqlite3');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const ini = require('ini');
|
const ini = require('ini');
|
||||||
const nostr = require('nostr-tools');
|
const nostr = require('nostr-tools');
|
||||||
|
@ -7,8 +6,6 @@ const wspf = require('websocket-polyfill');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
const xmpp = require('simple-xmpp');
|
const xmpp = require('simple-xmpp');
|
||||||
|
|
||||||
var db = new sqlite3.Database('nip26.db');
|
|
||||||
|
|
||||||
let {
|
let {
|
||||||
bech32,
|
bech32,
|
||||||
bech32m
|
bech32m
|
||||||
|
@ -24,6 +21,7 @@ if (fs.existsSync('./config.ini')) {
|
||||||
xmpp.on('online', function (data, to) {
|
xmpp.on('online', function (data, to) {
|
||||||
console.log('Connected with JID: ' + config.xmpp.jid);
|
console.log('Connected with JID: ' + config.xmpp.jid);
|
||||||
});
|
});
|
||||||
|
|
||||||
xmpp.on('chat', function (from, message) {
|
xmpp.on('chat', function (from, message) {
|
||||||
function debug() {
|
function debug() {
|
||||||
if (config.debug === '1') {
|
if (config.debug === '1') {
|
||||||
|
@ -32,63 +30,13 @@ if (fs.existsSync('./config.ini')) {
|
||||||
console.log(from);
|
console.log(from);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Add NIP-05, to get users latest kind 3, and notes.
|
if (message === '!help') {
|
||||||
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") {
|
|
||||||
xmpp.send(from, "reauth (nip-26)");
|
|
||||||
|
|
||||||
const now = new Date();
|
} else if (message === "!auth") {
|
||||||
const validUntil = now.getTime() + (30 * 24 * 60 * 60 * 1000);
|
xmpp.send(from, "https://auth.nostrsms.com");
|
||||||
const insertStmt = db.prepare('INSERT INTO users (pnum, token) VALUES (?, ?)');
|
|
||||||
insertStmt.run(from.split("@")[0], validUntil);
|
|
||||||
insertStmt.finalize();
|
|
||||||
debug();
|
|
||||||
} else {
|
} else {
|
||||||
async function newPost() {
|
async function newPost() {
|
||||||
const relay = nostr.relayInit(config.relays.write, WebSocket);
|
const relay = nostr.relayInit(config.relays.write, WebSocket);
|
||||||
|
@ -105,7 +53,7 @@ if (fs.existsSync('./config.ini')) {
|
||||||
kind: 1,
|
kind: 1,
|
||||||
pubkey: pk,
|
pubkey: pk,
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
tags: [],
|
tags: [['client','NostrSMS','31990:9be1b8315248eeb20f9d9ab2717d1750e4f27489eab1fa531d679dadd34c2f8d:1726937516']],
|
||||||
content: message,
|
content: message,
|
||||||
};
|
};
|
||||||
const signedEvent = nostr.finishEvent(event, sk);
|
const signedEvent = nostr.finishEvent(event, sk);
|
||||||
|
@ -128,6 +76,7 @@ if (fs.existsSync('./config.ini')) {
|
||||||
};
|
};
|
||||||
const encodedNEvent = nostr.nip19.neventEncode(event);
|
const encodedNEvent = nostr.nip19.neventEncode(event);
|
||||||
xmpp.send(from, "nostr:" + encodedNEvent);
|
xmpp.send(from, "nostr:" + encodedNEvent);
|
||||||
|
console.log(encodedNEvent)
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
nip26.db.dist
BIN
nip26.db.dist
Binary file not shown.
Loading…
Reference in New Issue
Block a user