-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbot.js
More file actions
74 lines (65 loc) · 1.91 KB
/
Copy pathbot.js
File metadata and controls
74 lines (65 loc) · 1.91 KB
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
require('./config/ImportEnv');
const Twit = require('twit');
const config = {
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 Twitter = new Twit(config);
const retweet = (searchTag) => {
const params = {
q: searchTag,
result_type: 'mixed',
count: 200,
};
Twitter.get('search/tweets', params, (srcErr, srcData, srcRes) => {
const tweets = srcData.statuses;
if (!srcErr) {
let tweetIDList = [];
tweets.forEach((tweet) => {
if (tweet.text.startsWith('RT @')) {
if (tweet.retweeted_status) {
tweetIDList.push(tweet.retweeted_status.id_str);
} else {
tweetIDList.push(tweet.id_str);
}
} else {
tweetIDList.push(tweet.id_str);
}
});
// Filter unique tweet IDs.
tweetIDList = tweetIDList.filter((value, index, self) => self.indexOf(value) === index);
tweetIDList.forEach((tweetID) => {
// Retweet
Twitter.post('statuses/retweet/:id', {
id: tweetID,
}, (rtErr, rtData, rtRes) => {
if (!rtErr || rtData) {
console.log(`\n\nRetweeted! ID - ${tweetID}`);
} else {
console.log(`\nError... Duplication maybe... ${tweetID}`);
}
});
/*
// Like a tweet
Twitter.post('favorites/create', {
id: tweetID,
})
.then(() => {
console.log('Liked tweet successfully!');
}).catch(() => {
console.log('Already Liked this tweet.');
});
*/
});
} else {
console.log(`Error while searching: ${srcErr}`);
process.exit(1);
}
});
};
// Run every 60 seconds
setInterval(() => {
retweet('#javascript OR #nodejs OR #100DaysOfCode OR #NanoSoft');
}, 60000);