-
Notifications
You must be signed in to change notification settings - Fork 17
/
app.js
52 lines (44 loc) · 1.35 KB
/
app.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
var config = require('./config.json');
var Twitter = require('twitter');
function DeleteTrump(api) {
this.client = new Twitter(api);
}
DeleteTrump.prototype = {
startStream: function() {
var self = this;
this.client.stream('statuses/filter', {
'follow': '25073877'
}, function (stream) {
console.log('STARTING DYA STREAM .... ');
self.stream = stream;
stream.on('data', function (tweet) {
// only reply to tweets _from_ user
if (!tweet.user || tweet.user.screen_name !== 'realDonaldTrump') return;
self.client.post('statuses/update', {
'in_reply_to_status_id': tweet.id_str,
status: '.@realDonaldTrump Delete your account.'
}, function (err) {
if (err) handleError(err);
console.log('REPLIED TO TRUMP\'s TWEET ', tweet.text);
console.log('');
});
});
stream.on('error', self.handleError.bind(self));
stream.on('end', self.resurrect.bind(self));
});
},
resurrect: function() {
this.stream = null
var self = this;
console.log('RESURRECTING STREAM');
setTimeout(function() {
self.startStream();
}, 1000 * 60 * 5 ); // wait 5 minutes
},
handleError: function(err) {
console.log(err);
process.exit();
}
}
var deleteTrump = new DeleteTrump(config.api);
deleteTrump.startStream();