forked from TechIsHiring/techishiring-twitter-bot-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.ts
42 lines (29 loc) · 1.07 KB
/
bot.ts
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
import { ETwitterStreamEvent } from "twitter-api-v2";
import twitterClient from "./config/config";
import { initializeBanList, checkIfBanned } from "./utils/banned/bannedUtils";
const TECHISHIRINGTWITTERID = "1392543731866390531"
const initializeBot = async () => {
let banList = await initializeBanList();
const stream = await twitterClient.v1.filterStream({
track: "#TechIsHiring",
autoConnect: true
});
stream.autoReconnect = true;
stream.keepAliveTimeoutMs = Infinity;
stream.on(ETwitterStreamEvent.Data, async (tweet) => {
console.log(tweet);
const notBanned = await checkIfBanned(tweet, banList);
if(notBanned){
try {
await twitterClient.v1.post("favorites/create.json", { id: tweet.id_str });
await twitterClient.v1.post(`statuses/retweet/${tweet.id_str}.json`);
return
} catch (error) {
return console.log(error);
}
}
console.log(`This tweet was not a permitted tweet: ${tweet.id_str}`);
});
setInterval(async () => banList = await initializeBanList(), 1800000);
};
initializeBot();