forked from vxmppb/vxmppb
checking for mqtt_enabled
Adding comments
This commit is contained in:
parent
b2444eb609
commit
d5dc804f60
20
index.js
20
index.js
|
@ -120,7 +120,9 @@ try {
|
||||||
console.log('Connected with JID: ' + bot_jid);
|
console.log('Connected with JID: ' + bot_jid);
|
||||||
//xmpp.send(user_jid, "[ONLINE]", false);
|
//xmpp.send(user_jid, "[ONLINE]", false);
|
||||||
// send mqtt online message
|
// send mqtt online message
|
||||||
client.publish(mqtt_topic, mqtt_message);
|
if (mqtt_enabled === "1"){
|
||||||
|
client.publish(mqtt_topic, mqtt_message);
|
||||||
|
}
|
||||||
// toot online message
|
// toot online message
|
||||||
if (mastodon_enabled === "1"){
|
if (mastodon_enabled === "1"){
|
||||||
M.post('statuses', {
|
M.post('statuses', {
|
||||||
|
@ -130,7 +132,7 @@ try {
|
||||||
});
|
});
|
||||||
// wait for incoming messages
|
// wait for incoming messages
|
||||||
xmpp.on('chat', function (from, message) {
|
xmpp.on('chat', function (from, message) {
|
||||||
// check for debugging
|
// check if user enabled asterisk
|
||||||
function call(call_data) {
|
function call(call_data) {
|
||||||
if (calls_enabled === '1') {
|
if (calls_enabled === '1') {
|
||||||
ami.action({
|
ami.action({
|
||||||
|
@ -143,7 +145,7 @@ try {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// check is user enabled debugging
|
||||||
function debug() {
|
function debug() {
|
||||||
if (debugging === '1') {
|
if (debugging === '1') {
|
||||||
console.log('[DEBUG]');
|
console.log('[DEBUG]');
|
||||||
|
@ -151,7 +153,7 @@ try {
|
||||||
console.log(from);
|
console.log(from);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// http request errors
|
||||||
function resError(error, res) {
|
function resError(error, res) {
|
||||||
if (!error && res.statusCode == 401) {
|
if (!error && res.statusCode == 401) {
|
||||||
console.log('Invalid credentials');
|
console.log('Invalid credentials');
|
||||||
|
@ -169,13 +171,13 @@ try {
|
||||||
// setup gotify url
|
// setup gotify url
|
||||||
let gotifyURL = `${gotify_api_url}/message?token=${gotify_key}&message=${from} ${gotify_message}&title=${gotify_title}&priority=${gotify_priority}`;
|
let gotifyURL = `${gotify_api_url}/message?token=${gotify_key}&message=${from} ${gotify_message}&title=${gotify_title}&priority=${gotify_priority}`;
|
||||||
let gotifyEUrl = encodeURI(gotifyURL);
|
let gotifyEUrl = encodeURI(gotifyURL);
|
||||||
// HELP
|
// !help reply
|
||||||
if (message === '!help') {
|
if (message === '!help') {
|
||||||
xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:commands');
|
xmpp.send(from, 'https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:commands');
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
|
|
||||||
// UNLOCKS
|
// !unlocks reply
|
||||||
else if (message === '!unlocks') {
|
else if (message === '!unlocks') {
|
||||||
if (from != user_jid) {
|
if (from != user_jid) {
|
||||||
xmpp.send(from, pc);
|
xmpp.send(from, pc);
|
||||||
|
@ -195,16 +197,20 @@ try {
|
||||||
if (error) {
|
if (error) {
|
||||||
return console.log(error)
|
return console.log(error)
|
||||||
};
|
};
|
||||||
|
// check for valid api response
|
||||||
if (!error && res.statusCode == 200) {
|
if (!error && res.statusCode == 200) {
|
||||||
var unlockBody = new RegExp(':(.*)}');
|
var unlockBody = new RegExp(':(.*)}');
|
||||||
var unlockBodyMatch = body.match(unlockBody);
|
var unlockBodyMatch = body.match(unlockBody);
|
||||||
|
// setup unlocks message
|
||||||
const unlockFinalMessage = user_name + " has " + unlockBodyMatch[1] + " unlocks for " + n;
|
const unlockFinalMessage = user_name + " has " + unlockBodyMatch[1] + " unlocks for " + n;
|
||||||
xmpp.send(from, unlockFinalMessage);
|
xmpp.send(from, unlockFinalMessage);
|
||||||
|
// call user with unlocks if asterisk enabled
|
||||||
call(unlockFinalMessage);
|
call(unlockFinalMessage);
|
||||||
}
|
}
|
||||||
|
// check for http errors
|
||||||
resError(error, res);
|
resError(error, res);
|
||||||
});
|
});
|
||||||
|
// output xmpp, and request errors if debugging is enabled.
|
||||||
debug();
|
debug();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user