forked from vxmppb/vxmppb
Compare commits
No commits in common. "2aafdd6c42c088001387ad357991e81d23848ac2" and "2e1b02f955bdd4a1b7f93f9ce6df1e65ecfa1ba7" have entirely different histories.
2aafdd6c42
...
2e1b02f955
|
@ -0,0 +1,21 @@
|
|||
pipeline {
|
||||
agent any
|
||||
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo 'Building..'
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
echo 'Testing..'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
echo 'Deploying....'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,7 +42,6 @@ bright_url =
|
|||
color_url =
|
||||
status_url =
|
||||
toggle_url =
|
||||
reauth_url
|
||||
|
||||
[unlocks]
|
||||
api_url =
|
||||
|
|
112
index.js
112
index.js
|
@ -59,7 +59,6 @@ try {
|
|||
const tuya_color_url = config.tuya.color_url;
|
||||
const tuya_status_url = config.tuya.status_url;
|
||||
const tuya_toggle_url = config.tuya.toggle_url;
|
||||
const tuya_reauth_url = config.tuya.reauth_url;
|
||||
|
||||
// Unlocks API config
|
||||
const unlocks_api_url = config.unlocks.api_url;
|
||||
|
@ -135,21 +134,7 @@ try {
|
|||
console.log(from);
|
||||
console.log('-------------');
|
||||
};
|
||||
}
|
||||
function resError(error,res){
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
};
|
||||
}
|
||||
// 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);
|
||||
|
@ -185,8 +170,20 @@ try {
|
|||
var unlockBodyMatch = body.match(unlockBody);
|
||||
const unlockFinalMessage = user_name + " has " + unlockBodyMatch[1] + " unlocks for " + n;
|
||||
xmpp.send(from, unlockFinalMessage);
|
||||
debug();
|
||||
}
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
resError(error,res);
|
||||
});
|
||||
debug();
|
||||
}
|
||||
|
@ -263,24 +260,18 @@ try {
|
|||
console.log("Tuya API: Unknown reply!");
|
||||
}
|
||||
}
|
||||
resError(error,res);
|
||||
});
|
||||
debug();
|
||||
}
|
||||
} else if (message === '!lightsauth') {
|
||||
if (from != user_jid) {
|
||||
xmpp.send(from, pc);
|
||||
} else {
|
||||
// refresh tokens for Tuya API
|
||||
request(tuya_reauth_url, (error, res, body) => {
|
||||
if (error) {
|
||||
return console.log(error)
|
||||
};
|
||||
|
||||
if (!error && res.statusCode == 200) {
|
||||
xmpp.send(from, 'Refreshing Tuya API auth keys');
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please !ping');
|
||||
}
|
||||
resError(error,res);
|
||||
});
|
||||
debug();
|
||||
}
|
||||
|
@ -299,7 +290,18 @@ try {
|
|||
xmpp.send(from, stat);
|
||||
console.log(stat);
|
||||
}
|
||||
resError(error,res);
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
});
|
||||
debug();
|
||||
}
|
||||
|
@ -312,12 +314,24 @@ try {
|
|||
if (error) {
|
||||
return console.log(error)
|
||||
};
|
||||
|
||||
if (!error && res.statusCode == 200) {
|
||||
const stat = tuya_name + " has been turned off";
|
||||
xmpp.send(from, stat);
|
||||
console.log(stat);
|
||||
}
|
||||
resError(error,res);
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
});
|
||||
debug();
|
||||
}
|
||||
|
@ -337,7 +351,18 @@ try {
|
|||
xmpp.send(from, tuya_name + "set to " + per + "%");
|
||||
console.log(tuya_name + "set to " + per + "%");
|
||||
}
|
||||
resError(error,res);
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
});
|
||||
if (config.debug === '1') {
|
||||
console.log('lights turned to ' + per + "%");
|
||||
|
@ -365,7 +390,18 @@ try {
|
|||
xmpp.send(from, tuya_name + "set to " + color);
|
||||
console.log(tuya_name + "set to " + color);
|
||||
}
|
||||
resError(error,res);
|
||||
if (!error && res.statusCode == 401) {
|
||||
console.log('Invalid credentials');
|
||||
xmpp.send(from, 'Invalid credentials');
|
||||
}
|
||||
if (!error && res.statusCode == 404) {
|
||||
console.log('Record not found');
|
||||
xmpp.send(from, 'Record not found');
|
||||
}
|
||||
if (!error && res.statusCode == 500) {
|
||||
console.log('Server error.');
|
||||
xmpp.send(from, 'Server error. Please ping admin');
|
||||
}
|
||||
});
|
||||
if (config.debug === '1') {
|
||||
console.log(tuya_name + "set to " + color);
|
||||
|
|
Reference in New Issue