-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
77 lines (68 loc) · 2.43 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
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
require("dotenv").config();
const Twit = require("twit");
const TwitBot = 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
});
const reTweet = (searchText) => {
let params = {
q: searchText + "",
result_type: "recent",
count: 25,
lang: "en"
}
TwitBot.get("search/tweets", params, (er, data, resp) => {
console.log("searching:)");
let tweets = data.statuses;
if(!er) {
let tweetIDList = [];
for(let tweet of tweets) {
tweetIDList.push(tweet.id_str);
// To Avoid Duplication
if(tweet.text.startsWith("RT @")) {
// if this true the already retweeted by bot
if(tweet.retweeted_status) {
tweetIDList.push(tweet.retweeted_status.id_str);
} else {
tweetIDList.push(tweet.id_str);
}
} else {
tweetIDList.push(tweet.id_str);
}
}
// unique tweets only
const uniqueTweets = (val, index, self) => {
return self.indexOf(val) === index;
}
tweetIDList = tweetIDList.filter(uniqueTweets);
for(let tweetID of tweetIDList) {
TwitBot.post("statuses/retweet/:id", {id: tweetID}, (err, dataRt, response) => {
if(!err) {
console.log("Retweeted id: ", tweetID);
} else {
console.log("Duplication maybe.", tweetID);
// console.log("Err: ", err);
}
});
// like tweet
TwitBot.post("favorites/create", {id: tweetID}, (err_fav, err_resp) => {
if(err_fav) {
// console.log("Some Error:", err_fav);
console.log("Some Error:");
} else {
console.log("favorited: ", tweetID);
}
});
}
} else {
console.log("Error while searching::", er);
process.exit(1);
}
})
}
setInterval(() => {
reTweet("#NodeJs");
reTweet("#100DaysOfCode");
}, 60000);