-
Notifications
You must be signed in to change notification settings - Fork 4
/
community-retweet-bot.js
82 lines (69 loc) · 2.04 KB
/
community-retweet-bot.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
var express = require('express'),
http = require('http'),
app = express(),
server = http.Server(app),
config = require('./config'),
Twit = require('twit'),
tweetQueue = [];
var loggingEnabled = true;
function checkTweetQueue(){
if (tweetQueue.length > 0){
var newTweet = tweetQueue.shift();
if (loggingEnabled === true){
console.log('Posting new tweet:');
console.log(newTweet);
}
twitter.post('statuses/retweet/:id',
{
id: newTweet.id
}, function(err, data, response) {
if (loggingEnabled === true){
if (err){
console.log('ERROR');
console.log(err);
}
else{
console.log('NO ERROR');
}
}
});
}
setTimeout(function(){
checkTweetQueue();
}, 36000);
}
var twitter = new Twit(config.twitter),
stream = twitter.stream('statuses/filter', { track: [
'@botwikidotorg'
// '#botally'
]
});
stream.on('tweet', function (tweet) {
var whiteList = [];
twitter.get('friends/ids', { screen_name: 'botwikidotorg', stringify_ids: true }, function (err, data, response) {
(function(tweet){
if (data.ids.indexOf(tweet.user.id_str) > -1){
if (loggingEnabled === true){
console.log('New Tweet!');
console.log(tweet.id + ': ' + tweet.text);
}
tweetQueue.push({
id: tweet.id_str
});
}
else{
if (loggingEnabled === true){
console.log('User not whitelisted.');
}
}
})(tweet);
});
});
checkTweetQueue();
app.get('/', function (req, res) {
res.send('Hello, I\'m running the <a href="https://twitter.com/botwikidotorg">@botwikidotorg</a> bot!');
});
app.use(express.static(__dirname + '/public'));
server.listen(3007, function(){
console.log('Express server listening on port 3007');
});