This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
127 lines (115 loc) · 3.67 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var Twit = require("twit");
const dotenv = require("dotenv");
const { sleep, isSpam, isValuable } = require("./utility");
const { keywords, accountsToFollow } = require("./config");
dotenv.config();
var T = new Twit({
consumer_key: process.env.BOT_CONSUMER_KEY,
consumer_secret: process.env.BOT_CONSUMER_SECRET,
access_token: process.env.BOT_ACCESS_TOKEN,
access_token_secret: process.env.BOT_ACCESS_TOKEN_SECRET,
timeout_ms: 60 * 1000,
});
//local variables
var counter = 0;
var likeCount = 0;
var retweetCount = 0;
const likeStream = T.stream("statuses/filter", { track: keywords });
const retweetStream = T.stream("statuses/filter", { follow: accountsToFollow });
console.log("Started....");
function startLikeStream() {
likeStream.start();
}
function startRetweetStream() {
retweetStream.start();
}
function like(favId) {
T.post("favorites/create", { id: favId }, async (err, response) => {
if (response.favorited) {
counter += 1;
likeCount += 1;
console.log(
likeCount.toString() +
" Liked Tweet - " +
response.id_str +
" by - @" +
response.user.screen_name
);
if (likeCount > 275) {
console.log("Sleeping for next 2 hours likeCount = " + likeCount);
likeCount = 0;
likeStream.stop();
setTimeout(startLikeStream, 1000 * 60 * 60 * 2);
}
await sleep(1000);
} else if (err) {
if (err.code == 226 || err.code == 205) {
console.error("You fucked up!");
likeStream.stop();
process.exit(0);
} else if (err.statusCode == 139) {
console.error("Liked this tweet already!");
} else if (err.code == 283) {
console.error(err.message);
likeStream.stop();
console.log("Going to sleep .... likeCount = " + likeCount);
setTimeout(startLikeStream, 1000 * 60 * 60 * 2);
} else {
console.error("Error: id - " + favId + " Message: " + err.message);
}
}
});
}
function retweet(tweetId) {
T.post("favorites/create", { id: tweetId }, async (err, response) => {
if (response.favorited) {
counter += 1;
retweetCount += 1;
console.log(
retweetCount.toString() +
" Retweeted Tweet - " +
response.id_str +
" by - @" +
response.user.screen_name
);
if (retweetCount > 275) {
console.log(
"Sleeping for next 2 hours retweet count = " + retweetCount
);
retweetCount = 0;
retweetStream.stop();
setTimeout(startRetweetStream, 1000 * 60 * 60 * 2);
}
await sleep(1000);
} else if (err) {
if (err.code == 226 || err.code == 205) {
console.error("You fucked up!");
retweetStream.stop();
process.exit(0);
} else if (err.statusCode == 139) {
console.error("Retweeted it already!");
} else if (err.code == 283) {
console.error(err.message);
retweetStream.stop();
console.log("Going to sleep .... Retweet Count = " + retweetCount);
setTimeout(startRetweetStream, 1000 * 60 * 60 * 2);
} else {
console.error("Error: id - " + tweetId + " Message: " + err.message);
}
}
});
}
likeStream.on("tweet", (tweet) => {
if (!isSpam(tweet) && isValuable(tweet)) {
like(tweet.id_str);
} else {
console.log("Tweet not worth interacting id-" + tweet.id_str);
}
});
retweetStream.on("tweet", (tweet) => {
if (!isSpam(tweet)) {
retweet(tweet.id_str);
} else {
console.log("Tweet not worth interacting id-" + tweet.id_str);
}
});