From d5dc804f60b106d2df064002258ddd696bd54bb2 Mon Sep 17 00:00:00 2001 From: stephen Date: Thu, 26 May 2022 19:14:36 -0400 Subject: [PATCH] checking for mqtt_enabled Adding comments --- index.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index b39b590..618f5be 100755 --- a/index.js +++ b/index.js @@ -120,7 +120,9 @@ try { console.log('Connected with JID: ' + bot_jid); //xmpp.send(user_jid, "[ONLINE]", false); // send mqtt online message - client.publish(mqtt_topic, mqtt_message); + if (mqtt_enabled === "1"){ + client.publish(mqtt_topic, mqtt_message); + } // toot online message if (mastodon_enabled === "1"){ M.post('statuses', { @@ -130,7 +132,7 @@ try { }); // wait for incoming messages xmpp.on('chat', function (from, message) { - // check for debugging + // check if user enabled asterisk function call(call_data) { if (calls_enabled === '1') { ami.action({ @@ -143,7 +145,7 @@ try { }); } } - + // check is user enabled debugging function debug() { if (debugging === '1') { console.log('[DEBUG]'); @@ -151,7 +153,7 @@ try { console.log(from); }; } - + // http request errors function resError(error, res) { if (!error && res.statusCode == 401) { console.log('Invalid credentials'); @@ -169,13 +171,13 @@ try { // setup gotify url let gotifyURL = `${gotify_api_url}/message?token=${gotify_key}&message=${from} ${gotify_message}&title=${gotify_title}&priority=${gotify_priority}`; let gotifyEUrl = encodeURI(gotifyURL); - // HELP + // !help reply if (message === '!help') { xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:commands'); debug(); } - // UNLOCKS + // !unlocks reply else if (message === '!unlocks') { if (from != user_jid) { xmpp.send(from, pc); @@ -195,16 +197,20 @@ try { if (error) { return console.log(error) }; - + // check for valid api response if (!error && res.statusCode == 200) { var unlockBody = new RegExp(':(.*)}'); var unlockBodyMatch = body.match(unlockBody); + // setup unlocks message const unlockFinalMessage = user_name + " has " + unlockBodyMatch[1] + " unlocks for " + n; xmpp.send(from, unlockFinalMessage); + // call user with unlocks if asterisk enabled call(unlockFinalMessage); } + // check for http errors resError(error, res); }); + // output xmpp, and request errors if debugging is enabled. debug(); } }