forked from ttezel/twit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtd2.js
77 lines (63 loc) · 1.98 KB
/
rtd2.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
//
// RTD2 - Twitter bot that tweets about the most popular github.com news
// Also makes new friends and prunes its followings.
//
var Bot = require('./bot')
, config1 = require('../config1');
var bot = new Bot(config1);
console.log('RTD2: Running.');
//get date string for today's date (e.g. '2011-01-01')
function datestring () {
var d = new Date(Date.now() - 5*60*60*1000); //est timezone
return d.getUTCFullYear() + '-'
+ (d.getUTCMonth() + 1) + '-'
+ d.getDate();
};
setInterval(function() {
bot.twit.get('followers/ids', function(err, reply) {
if(err) return handleError(err)
console.log('\n# followers:' + reply.ids.length.toString());
});
var rand = Math.random();
if(rand <= 0.10) { // tweet popular github tweet
var params = {
q: 'github.com/'
, since: datestring()
, result_type: 'mixed'
};
bot.twit.get('search/tweets', params, function (err, reply) {
if(err) return handleError(err);
var max = 0, popular;
var tweets = reply.statuses
, i = tweets.length;
while(i--) {
var tweet = tweets[i]
, popularity = tweet.retweet_count;
if(popularity > max) {
max = popularity;
popular = tweet.text;
}
}
bot.tweet(popular, function (err, reply) {
if(err) return handleError(err);
console.log('\nTweet: ' + (reply ? reply.text : reply));
})
});
} else if(rand <= 0.55) { // make a friend
bot.mingle(function(err, reply) {
if(err) return handleError(err);
var name = reply.screen_name;
console.log('\nMingle: followed @' + name);
});
} else { // prune a friend
bot.prune(function(err, reply) {
if(err) return handleError(err);
var name = reply.screen_name
console.log('\nPrune: unfollowed @'+ name);
});
}
}, 40000);
function handleError(err) {
console.error('response status:', err.statusCode);
console.error('data:', err.data);
}