-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
88 lines (80 loc) · 2.56 KB
/
index.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
const log = require("./lib/logger")("Twitter Monitor V1");
const path = require("path");
const twit = require("twit");
const request = require("request");
const notify = require("./lib/notify");
const config = require(path.join(__dirname, "config.json"));
// twitter configuration
var T = new twit({
consumer_key: config.app.consumer.key,
consumer_secret: config.app.consumer.secret,
access_token: config.app.access.token,
access_token_secret: config.app.access.secret
});
let headers = {
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.9",
"Upgrade-Insecure-Requests": "1",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36",
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Cache-Control": "max-age=0",
Connection: "keep-alive"
};
/* Start up function */
(function() {
const Twitter = {
userID: [],
tweetID: [],
init: function() {
this.connector().then(() => this.startMonitor());
},
connector: function() {
log.green("Initializing Twitter Monitor...");
return new Promise((resolve, reject) => {
config.app.other.twittername.forEach(name => {
T.get("/users/show", { screen_name: name }, (err, data, res) => {
if (err) {
reject();
return log.red("ERROR" + err);
}
this.userID.push(data.id_str);
if (this.userID.length == config.app.other.twittername.length) {
resolve();
}
});
});
});
},
startMonitor: function() {
var stream = T.stream("statuses/filter", {
follow: this.userID,
exclude_replies: true,
include_rts: false
});
stream.on("connected", res => {
log.green(
"Twitter Monitor is connected... ~ Currently monitoring " +
config.app.other.twittername.length +
" profiles"
);
});
stream.on("tweet", tweet => {
if (
!this.tweetID.includes(tweet.id_str) &&
this.userID.includes(tweet.user.id_str)
) {
this.tweetID.push(tweet.id_str);
log.green("****** TWEET DETECTED ******");
log.blue(`[USER: ${tweet.user.screen_name}] - Just tweeted!`);
log.blue(`[TIMESTAMP] - ${tweet.timestamp_ms}`);
log.yellow("Sent discord webhook!");
// notify user
notify(headers, tweet, config);
}
});
}
};
Twitter.init();
})();