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
|
||||
package-lock.json
|
||||
config.ini
|
||||
build/
|
||||
.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
|
||||
const sqlite3 = require('sqlite3');
|
||||
const fs = require('fs');
|
||||
const ini = require('ini');
|
||||
const nostr = require('nostr-tools');
|
||||
const wspf = require('websocket-polyfill');
|
||||
const WebSocket = require('ws');
|
||||
const xmpp = require('simple-xmpp');
|
||||
|
||||
var db = new sqlite3.Database('delegations.db');
|
||||
|
||||
let { bech32, bech32m } = require('bech32');
|
||||
let letsCID;
|
||||
let signedEvent;
|
||||
|
||||
if (fs.existsSync('./config.ini')) {
|
||||
const config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'));
|
||||
let sk = config.nostr.pkhex;
|
||||
let pk = nostr.getPublicKey(sk);
|
||||
|
||||
xmpp.on('online', function (data, to) {
|
||||
console.log('Connected with JID: ' + config.xmpp.jid);
|
||||
});
|
||||
xmpp.on('chat', function (from, message) {
|
||||
function debug() {
|
||||
if (config.debug === '1') {
|
||||
console.log('[DEBUG]');
|
||||
console.log(message);
|
||||
console.log(from);
|
||||
};
|
||||
}
|
||||
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)");
|
||||
|
||||
const now = new Date();
|
||||
const validUntil = now.getTime() + (30 * 24 * 60 * 60 * 1000);
|
||||
const insertStmt = db.prepare('INSERT INTO users (pnum, token) VALUES (?, ?)');
|
||||
insertStmt.run(from, validUntil);
|
||||
insertStmt.finalize();
|
||||
console.log('Data inserted successfully');
|
||||
db.close((err) => {
|
||||
if (err) {
|
||||
return console.error('Error closing the database:', err.message);
|
||||
}
|
||||
console.log('Database connection closed.');
|
||||
});
|
||||
debug();
|
||||
}
|
||||
else {
|
||||
async function main() {
|
||||
const relay = nostr.relayInit(config.relays.write, 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 event = {
|
||||
kind: 1,
|
||||
pubkey: pk,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [],
|
||||
content: message,
|
||||
};
|
||||
|
||||
const signedEvent = nostr.finishEvent(event, sk);
|
||||
letsCID = signedEvent.id;
|
||||
showSID(letsCID,pk);
|
||||
await relay.publish(signedEvent);
|
||||
relay.close();
|
||||
}
|
||||
|
||||
main().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:start");
|
||||
console.log("and choose your preferred install method.");
|
||||
}
|
||||
// initialize required packages
|
||||
const sqlite3 = require('sqlite3');
|
||||
const fs = require('fs');
|
||||
const ini = require('ini');
|
||||
const nostr = require('nostr-tools');
|
||||
const wspf = require('websocket-polyfill');
|
||||
const WebSocket = require('ws');
|
||||
const xmpp = require('simple-xmpp');
|
||||
|
||||
var db = new sqlite3.Database('nip26.db');
|
||||
|
||||
let {
|
||||
bech32,
|
||||
bech32m
|
||||
} = require('bech32');
|
||||
let letsCID;
|
||||
let signedEvent;
|
||||
|
||||
if (fs.existsSync('./config.ini')) {
|
||||
const config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'));
|
||||
let sk = config.nostr.pkhex;
|
||||
let pk = nostr.getPublicKey(sk);
|
||||
|
||||
xmpp.on('online', function (data, to) {
|
||||
console.log('Connected with JID: ' + config.xmpp.jid);
|
||||
});
|
||||
xmpp.on('chat', function (from, message) {
|
||||
function debug() {
|
||||
if (config.debug === '1') {
|
||||
console.log('[DEBUG]');
|
||||
console.log(message);
|
||||
console.log(from);
|
||||
};
|
||||
}
|
||||
// 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)");
|
||||
|
||||
const now = new Date();
|
||||
const validUntil = now.getTime() + (30 * 24 * 60 * 60 * 1000);
|
||||
const insertStmt = db.prepare('INSERT INTO users (pnum, token) VALUES (?, ?)');
|
||||
insertStmt.run(from.split("@")[0], validUntil);
|
||||
insertStmt.finalize();
|
||||
debug();
|
||||
} else {
|
||||
async function newPost() {
|
||||
const relay = nostr.relayInit(config.relays.write, 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 event = {
|
||||
kind: 1,
|
||||
pubkey: pk,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [],
|
||||
content: message,
|
||||
};
|
||||
const signedEvent = nostr.finishEvent(event, sk);
|
||||
letsCID = signedEvent.id;
|
||||
showSID(letsCID, pk);
|
||||
await relay.publish(signedEvent);
|
||||
relay.close();
|
||||
}
|
||||
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