Adding authorized user check for incoming messages.
This commit is contained in:
10
index.js
10
index.js
@@ -17,6 +17,9 @@ if (fs.existsSync('./config.ini')) {
|
|||||||
const config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'));
|
const config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'));
|
||||||
let sk = config.nostr.pkhex;
|
let sk = config.nostr.pkhex;
|
||||||
let pk = nostr.getPublicKey(sk);
|
let pk = nostr.getPublicKey(sk);
|
||||||
|
const authorizedUsers = config.authorized_users.users
|
||||||
|
? config.authorized_users.users.split(',').map(user => user.trim())
|
||||||
|
: [];
|
||||||
|
|
||||||
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);
|
||||||
@@ -31,6 +34,13 @@ if (fs.existsSync('./config.ini')) {
|
|||||||
console.log(from);
|
console.log(from);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!authorizedUsers.includes(from)) {
|
||||||
|
xmpp.send(from, 'Not authorized');
|
||||||
|
debug();
|
||||||
|
return; // Exit the function early
|
||||||
|
}
|
||||||
|
|
||||||
if (message === '!help') {
|
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();
|
||||||
|
Reference in New Issue
Block a user