forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushbullet.js
88 lines (73 loc) · 2.34 KB
/
pushbullet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* Created by rocketman1337345 on 8/14/16.
*/
var pushbullet = require("pushbullet");
var _ = require('lodash');
var log = require('../core/log.js');
var util = require('../core/util.js');
var config = util.getConfig();
var pushbulletConfig = config.pushbullet;
var Pushbullet = function(done) {
_.bindAll(this);
this.pusher;
this.price = 'N/A';
this.done = done;
this.setup();
};
Pushbullet.prototype.setup = function(done){
var setupPushBullet = function (err, result) {
if(pushbulletConfig.sendMessageOnStart){
var title = pushbulletConfig.tag;
var exchange = config.watch.exchange;
var currency = config.watch.currency;
var asset = config.watch.asset;
var body = "Gekko has started, Ive started watching "
+exchange
+" "
+currency
+" "
+asset
+" I'll let you know when I got some advice";
this.mail(title, body);
}else{
log.debug('Skipping Send message on startup')
}
};
setupPushBullet.call(this)
};
Pushbullet.prototype.processCandle = function(candle, done) {
this.price = candle.close;
done();
};
Pushbullet.prototype.processAdvice = function(advice) {
if (advice.recommendation == "soft" && pushbulletConfig.muteSoft) return;
var text = [
'Gekko is watching ',
config.watch.exchange,
' and has detected a new trend, advice is to go ',
advice.recommendation,
'.\n\nThe current ',
config.watch.asset,
' price is ',
this.price
].join('');
var subject = pushbulletConfig.tag+' New advice: go ' + advice.recommendation;
this.mail(subject, text);
};
Pushbullet.prototype.mail = function(subject, content, done) {
var pusher = new pushbullet(pushbulletConfig.key);
pusher.note(pushbulletConfig.email, subject, content, function(error, response) {
if(error || !response) {
log.error('Pushbullet ERROR:', error)
} else if(response && response.active){
log.info('Pushbullet Message Sent')
}
});
};
Pushbullet.prototype.checkResults = function(err) {
if(err)
log.warn('error sending email', err);
else
log.info('Send advice via email.');
};
module.exports = Pushbullet;