-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
48 lines (43 loc) · 1.42 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
//require two dependencies for our bot.js file
var Twit = require('twit');
var fs = require('fs');
//config file
var T = new Twit(require('./config.js'));
function randomInt (low, high) {
return Math.floor(Math.random() * (high - low) + low);
}
//URL of a search for the latest tweets on the '#arts' hashtag.
var artsSearch = {q: '"#machinelearning"OR "#MachineLearning"OR" #artificialintelligence"OR" #DeepLearning"OR" #AI' ,
count: 100,
result_type: "recent",
lang: 'en'
};
// This function finds the latest tweet with the #arts hashtag, and retweets it.
function retweet() {
T.get('search/tweets', artsSearch, function (error, data) {
console.log(error, data);
if (!error) {
//ID of tweet to retweet
var dat = randomInt(0,100);
//ID of the tweet we want to retweet...
var retweetId = data.statuses[dat].id_str;
//retweet
T.post('statuses/retweet/' + retweetId, { }, function (error, callback) {
if (callback) {
console.log('Success! Check your bot, it has retweeted something...')
}
//error
if (error) {
console.log('Error! Sorry about that:', error);
}
})
}
// However, if our original search request had an error, we want to print it out here.
else {
console.log('There was an error with your hashtag search:', error);
}
});
}
//start bot & timer (optional)
//retweet()
//setInterval(retweet, Math.floor(((Math.random() * 10) + 5) * 1000) * 60);