initial commit, added basically all basic functionality
This commit is contained in:
commit
8ef218c1ec
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
config.json
|
||||||
|
friends.txt
|
||||||
13
config.example.json
Normal file
13
config.example.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"pushover": {
|
||||||
|
"user": "",
|
||||||
|
"token": ""
|
||||||
|
},
|
||||||
|
"ts-notify": {
|
||||||
|
"address": "localhost",
|
||||||
|
"port": 6000,
|
||||||
|
"friendly_name": "",
|
||||||
|
"apikey": ""
|
||||||
|
},
|
||||||
|
"follow_file": ""
|
||||||
|
}
|
||||||
63
index.js
Normal file
63
index.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
const io = require('socket.io-client');
|
||||||
|
const push = require('pushover-notifications');
|
||||||
|
const util = require('util');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const configjson = require('./config.example.json');
|
||||||
|
|
||||||
|
const ts_notify = configjson["ts-notify"];
|
||||||
|
|
||||||
|
var p = new push({
|
||||||
|
user: configjson.pushover.user,
|
||||||
|
token: configjson.pushover.token
|
||||||
|
});
|
||||||
|
|
||||||
|
var address = "http://" + ts_notify.address + ":" + ts_notify.port;
|
||||||
|
var socket = io(address);
|
||||||
|
|
||||||
|
socket.on('connect', function() {
|
||||||
|
util.log("Connected to " + address);
|
||||||
|
|
||||||
|
socket.emit('apiaccess', ts_notify.apikey);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('event', function(evt) {
|
||||||
|
var friends = [];
|
||||||
|
if(configjson.follow_file != undefined || fs.existsSync(configjson.follow_file)) {
|
||||||
|
try {
|
||||||
|
var follow_file = fs.readFileSync(configjson.follow_file, {encoding: "UTF-8"});
|
||||||
|
friends = follow_file.trim().split('\n');
|
||||||
|
} catch(e) {
|
||||||
|
util.log("Error while reading friends file: " + err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(friends.indexOf(evt.uid) != -1) {
|
||||||
|
util.log(evt.name + " " + evt.status);
|
||||||
|
|
||||||
|
var message = evt.name + " " + evt.status;
|
||||||
|
if (ts_notify.friendly_name != undefined || ts_notify.friendly_name != "") {
|
||||||
|
if (evt.status == "connected") {
|
||||||
|
message += " to ";
|
||||||
|
} else if (evt.status == "disconnected") {
|
||||||
|
message += " from ";
|
||||||
|
} else {
|
||||||
|
message += " at ";
|
||||||
|
}
|
||||||
|
message += ts_notify.friendly_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.send({
|
||||||
|
message: message
|
||||||
|
}, function(err, result) {
|
||||||
|
if(err) {
|
||||||
|
util.log("Error while sending push: " + err.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function htmlEntities(str) {
|
||||||
|
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(new RegExp('"', 'g'), '"');
|
||||||
|
}
|
||||||
19
package.json
Normal file
19
package.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "ts-notify-pushover",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Provides a link between the ts-notify-server and the Pushover service",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git@j4ns.de:git/ts-notify-pushover.git"
|
||||||
|
},
|
||||||
|
"author": "jangxx <janscheiper95@gmail.com> (http://www.jangxx.com)",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"pushover-notifications": "^0.2.4",
|
||||||
|
"socket.io-client": "^2.0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user