Compare commits
13 Commits
no_delegat
...
main
Author | SHA1 | Date | |
---|---|---|---|
b27fcf8308 | |||
dfc3985f9d | |||
92da7fb1e8 | |||
916df48627 | |||
b4d798f7f2 | |||
daa19a06be | |||
872e79e3a1 | |||
0b3895edcc | |||
a4ee893af5 | |||
4deaaeef88 | |||
e26e221a85 | |||
5cf12e2209 | |||
9d1016e383 |
29
.dockerignore
Normal file
29
.dockerignore
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
**/.classpath
|
||||||
|
**/.dockerignore
|
||||||
|
**/.env
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
**/.project
|
||||||
|
**/.settings
|
||||||
|
**/.toolstarget
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
**/.next
|
||||||
|
**/.cache
|
||||||
|
**/*.*proj.user
|
||||||
|
**/*.dbmdl
|
||||||
|
**/*.jfm
|
||||||
|
**/charts
|
||||||
|
**/docker-compose*
|
||||||
|
**/compose*
|
||||||
|
**/Dockerfile*
|
||||||
|
**/node_modules
|
||||||
|
**/npm-debug.log
|
||||||
|
**/obj
|
||||||
|
**/secrets.dev.yaml
|
||||||
|
**/values.dev.yaml
|
||||||
|
**/build
|
||||||
|
**/dist
|
||||||
|
LICENSE
|
||||||
|
README.md
|
||||||
|
config.ini
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,4 @@
|
||||||
node_modules
|
node_modules
|
||||||
package-lock.json
|
|
||||||
config.ini
|
config.ini
|
||||||
build/
|
build/
|
||||||
.npmignore
|
.npmignore
|
||||||
|
|
6
Dockerfile
Normal file
6
Dockerfile
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
FROM node:16-alpine
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install
|
||||||
|
COPY . .
|
||||||
|
CMD ["node", "index.js"]
|
272
index.js
272
index.js
|
@ -1,118 +1,154 @@
|
||||||
// initialize required packages
|
// initialize required packages
|
||||||
const sqlite3 = require('sqlite3');
|
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');
|
||||||
const wspf = require('websocket-polyfill');
|
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('delegations.db');
|
var db = new sqlite3.Database('nip26.db');
|
||||||
|
|
||||||
let { bech32, bech32m } = require('bech32');
|
let {
|
||||||
let letsCID;
|
bech32,
|
||||||
let signedEvent;
|
bech32m
|
||||||
|
} = require('bech32');
|
||||||
if (fs.existsSync('./config.ini')) {
|
let letsCID;
|
||||||
const config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'));
|
let signedEvent;
|
||||||
let sk = config.nostr.pkhex;
|
|
||||||
let pk = nostr.getPublicKey(sk);
|
if (fs.existsSync('./config.ini')) {
|
||||||
|
const config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'));
|
||||||
xmpp.on('online', function (data, to) {
|
let sk = config.nostr.pkhex;
|
||||||
console.log('Connected with JID: ' + config.xmpp.jid);
|
let pk = nostr.getPublicKey(sk);
|
||||||
});
|
|
||||||
xmpp.on('chat', function (from, message) {
|
xmpp.on('online', function (data, to) {
|
||||||
function debug() {
|
console.log('Connected with JID: ' + config.xmpp.jid);
|
||||||
if (config.debug === '1') {
|
});
|
||||||
console.log('[DEBUG]');
|
xmpp.on('chat', function (from, message) {
|
||||||
console.log(message);
|
function debug() {
|
||||||
console.log(from);
|
if (config.debug === '1') {
|
||||||
};
|
console.log('[DEBUG]');
|
||||||
}
|
console.log(message);
|
||||||
if (message === '!help') {
|
console.log(from);
|
||||||
xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:nostrsms:commands');
|
};
|
||||||
debug();
|
}
|
||||||
}
|
// Add NIP-05, to get users latest kind 3, and notes.
|
||||||
else if (message === "!auth"){
|
if (message === "!fetch") {
|
||||||
xmpp.send(from,"reauth (nip-26)");
|
xmpp.send(from, "Sure. Please standby...");
|
||||||
|
async function gogoGlobalShoes() {
|
||||||
const now = new Date();
|
const relay = nostr.relayInit(config.relays.read, WebSocket);
|
||||||
const validUntil = now.getTime() + (30 * 24 * 60 * 60 * 1000);
|
relay.on('connect', () => {
|
||||||
const insertStmt = db.prepare('INSERT INTO users (pnum, token) VALUES (?, ?)');
|
console.log(`connected to ${relay.url}`);
|
||||||
insertStmt.run(from, validUntil);
|
});
|
||||||
insertStmt.finalize();
|
relay.on('error', () => {
|
||||||
console.log('Data inserted successfully');
|
console.log(`failed to connect to ${relay.url}`);
|
||||||
db.close((err) => {
|
});
|
||||||
if (err) {
|
|
||||||
return console.error('Error closing the database:', err.message);
|
await relay.connect();
|
||||||
}
|
|
||||||
console.log('Database connection closed.');
|
let sub = relay.sub([{
|
||||||
});
|
kinds: [1],
|
||||||
debug();
|
authors: [pk],
|
||||||
}
|
limit: 5
|
||||||
else {
|
}, ])
|
||||||
async function main() {
|
sub.on('event', event => {
|
||||||
const relay = nostr.relayInit(config.relays.write, WebSocket);
|
console.log('got event:', event);
|
||||||
relay.on('connect', () => {
|
|
||||||
console.log(`connected to ${relay.url}`);
|
// Check if the event is already an object
|
||||||
});
|
const conny = typeof event === 'string' ? JSON.parse(event) : event;
|
||||||
relay.on('error', () => {
|
|
||||||
console.log(`failed to connect to ${relay.url}`);
|
if (conny && conny.content && conny.pubkey && conny.created_at) {
|
||||||
});
|
const content = conny.content;
|
||||||
|
const author = conny.pubkey;
|
||||||
await relay.connect();
|
const createdAt = conny.created_at;
|
||||||
|
|
||||||
let event = {
|
// Use the extracted properties as needed
|
||||||
kind: 1,
|
console.log('Content:', content);
|
||||||
pubkey: pk,
|
console.log('Author:', author);
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
console.log('Created At:', createdAt);
|
||||||
tags: [],
|
|
||||||
content: message,
|
// You can send these properties via XMPP or perform other actions here
|
||||||
};
|
xmpp.send(from, `\"${content}\", - ${author} @ ${createdAt}`);
|
||||||
|
} else {
|
||||||
const signedEvent = nostr.finishEvent(event, sk);
|
console.error('Invalid event structure or missing required properties.');
|
||||||
letsCID = signedEvent.id;
|
}
|
||||||
showSID(letsCID,pk);
|
});
|
||||||
await relay.publish(signedEvent);
|
}
|
||||||
relay.close();
|
gogoGlobalShoes().catch((error) => {
|
||||||
}
|
console.error(error);
|
||||||
|
});
|
||||||
main().catch((error) => {
|
} else if (message === '!help') {
|
||||||
console.error(error);
|
xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:nostrsms:commands');
|
||||||
});
|
debug();
|
||||||
|
} else if (message === "!auth") {
|
||||||
async function showSID(letsCID,pk) {
|
xmpp.send(from, "reauth (nip-26)");
|
||||||
console.log(letsCID);
|
|
||||||
console.log(pk);
|
const now = new Date();
|
||||||
const event = {
|
const validUntil = now.getTime() + (30 * 24 * 60 * 60 * 1000);
|
||||||
id: letsCID,
|
const insertStmt = db.prepare('INSERT INTO users (pnum, token) VALUES (?, ?)');
|
||||||
relays: [config.relays.write],
|
insertStmt.run(from.split("@")[0], validUntil);
|
||||||
author: pk,
|
insertStmt.finalize();
|
||||||
kind: 1,
|
debug();
|
||||||
};
|
} else {
|
||||||
const encodedNEvent = nostr.nip19.neventEncode(event);
|
async function newPost() {
|
||||||
xmpp.send(from, "nostr:" + encodedNEvent);
|
const relay = nostr.relayInit(config.relays.write, WebSocket);
|
||||||
debug();
|
relay.on('connect', () => {
|
||||||
}
|
console.log(`connected to ${relay.url}`);
|
||||||
}
|
});
|
||||||
});
|
relay.on('error', () => {
|
||||||
xmpp.on('error', function (err) {
|
console.log(`failed to connect to ${relay.url}`);
|
||||||
console.error(err);
|
});
|
||||||
});
|
|
||||||
xmpp.setPresence('chat', 'https://nostrsms.com');
|
await relay.connect();
|
||||||
xmpp.connect({
|
|
||||||
jid: config.xmpp.jid,
|
let event = {
|
||||||
password: config.xmpp.password,
|
kind: 1,
|
||||||
host: config.xmpp.host,
|
pubkey: pk,
|
||||||
port: 5222
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
});
|
tags: [],
|
||||||
process.on('SIGINT', function() {
|
content: message,
|
||||||
console.log("SigInt receieved. Shutdown inevitable!")
|
};
|
||||||
process.exit();
|
const signedEvent = nostr.finishEvent(event, sk);
|
||||||
});
|
letsCID = signedEvent.id;
|
||||||
|
showSID(letsCID, pk);
|
||||||
} else {
|
await relay.publish(signedEvent);
|
||||||
console.log("Please create a config.ini");
|
relay.close();
|
||||||
console.log("See https://wiki.vanderwarker.family/doku.php?id=code:nostrsms:install:start");
|
}
|
||||||
console.log("and choose your preferred install method.");
|
newPost().catch((error) => {
|
||||||
}
|
console.error(error);
|
||||||
|
});
|
||||||
|
async function showSID(letsCID, pk) {
|
||||||
|
console.log(letsCID);
|
||||||
|
console.log(pk);
|
||||||
|
const event = {
|
||||||
|
id: letsCID,
|
||||||
|
relays: [config.relays.write],
|
||||||
|
author: pk,
|
||||||
|
kind: 1,
|
||||||
|
};
|
||||||
|
const encodedNEvent = nostr.nip19.neventEncode(event);
|
||||||
|
xmpp.send(from, "nostr:" + encodedNEvent);
|
||||||
|
debug();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
xmpp.on('error', function (err) {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
xmpp.setPresence('chat', 'https://nostrsms.com');
|
||||||
|
xmpp.connect({
|
||||||
|
jid: config.xmpp.jid,
|
||||||
|
password: config.xmpp.password,
|
||||||
|
host: config.xmpp.host,
|
||||||
|
port: 5222
|
||||||
|
});
|
||||||
|
process.on('SIGINT', function () {
|
||||||
|
console.log("SigInt receieved. Shutdown inevitable!")
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("Please create a config.ini");
|
||||||
|
console.log("See https://wiki.vanderwarker.family/doku.php?id=code:nostrsms:install");
|
||||||
|
console.log("and choose your preferred install method.");
|
||||||
|
}
|
BIN
nip26.db.dist
Normal file
BIN
nip26.db.dist
Normal file
Binary file not shown.
2361
package-lock.json
generated
Normal file
2361
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user