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'));
|
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);
|
||||||
console.log('Pubkey: ' + pk);
|
console.log('Pubkey: ' + pk);
|
||||||
});
|
});
|
||||||
|
|
||||||
xmpp.on('chat', function (from, message) {
|
xmpp.on('chat', function (from, message) {
|
||||||
function debug() {
|
function debug() {
|
||||||
if (config.debug === '1') {
|
if (config.debug === '1') {
|
||||||
@ -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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user