-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
61 lines (53 loc) · 1.51 KB
/
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
var Twit = require('twit');
// use following two lines for running locally. Or you can run 'heroku local' if using heroku.
// var config = require('./config');
// var T = new Twit(config);
var T = new Twit({
consumer_key: process.env.consumer_key,
consumer_secret: process.env.consumer_secret,
access_token: process.env.access_token,
access_token_secret: process.env.access_token_secret
});
var trumpTwitter = 25073877;
// listens for Trump Tweets and quotes them with a boo
var stream = T.stream('statuses/filter', { follow: trumpTwitter });
stream.on('tweet', tweetEvent);
function tweetEvent(event) {
var id = event.id_str;
var text = event.text;
var user = event.user.screen_name;
var userID = event.user.id;
var boo = booGenerator();
if (userID === trumpTwitter) {
console.log(text);
var quotedTweet = boo + ' https://twitter.com/' + user + '/status/' + id;
doATweet(quotedTweet);
}
};
// Gets a random number
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
};
// Gdds a user-specified number of 'o's to boo
function booGenerator() {
var booBegin = "b"
for (var i = 0; i < getRandomInt(2, 10); i++) {
booBegin+= "o"
}
return booBegin;
};
// Tweet function
function doATweet(text) {
var tweet = {
status: text
};
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log('Uh oh!');
}
else {
console.log('Looking good!');
}
}
};