checking for mqtt_enabled

Adding comments
This commit is contained in:
Stephen Vanderwarker 2022-05-26 19:14:36 -04:00
parent b2444eb609
commit d5dc804f60
Signed by: stephen
GPG Key ID: EF429EF847868C14
1 changed files with 13 additions and 7 deletions

View File

@ -120,7 +120,9 @@ try {
console.log('Connected with JID: ' + bot_jid);
//xmpp.send(user_jid, "[ONLINE]", false);
// send mqtt online 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();
}
}