Adding authorized user check for incoming messages.
This commit is contained in:
parent
d4e4e3206f
commit
942e919102
12
index.js
12
index.js
@ -17,12 +17,15 @@ 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);
|
||||
const authorizedUsers = config.authorized_users.users
|
||||
? config.authorized_users.users.split(',').map(user => user.trim())
|
||||
: [];
|
||||
|
||||
xmpp.on('online', function (data, to) {
|
||||
console.log('Connected with JID: ' + config.xmpp.jid);
|
||||
console.log('Pubkey: ' + pk);
|
||||
});
|
||||
|
||||
|
||||
xmpp.on('chat', function (from, message) {
|
||||
function debug() {
|
||||
if (config.debug === '1') {
|
||||
@ -31,6 +34,13 @@ if (fs.existsSync('./config.ini')) {
|
||||
console.log(from);
|
||||
};
|
||||
}
|
||||
|
||||
if (!authorizedUsers.includes(from)) {
|
||||
xmpp.send(from, 'Not authorized');
|
||||
debug();
|
||||
return; // Exit the function early
|
||||
}
|
||||
|
||||
if (message === '!help') {
|
||||
xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:nostrsms:commands');
|
||||
debug();
|
||||
|
Loading…
x
Reference in New Issue
Block a user