-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
194 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,173 +1,81 @@ | ||
/* Special Thank you to _luqy or matt, don't know you but, I want to give you credit! */ | ||
|
||
/* LINE: 108; just do another if statement to check if keyword does not match, which means we get anything the user tweets from most recent! */ | ||
|
||
try { | ||
require("console-stamp")(console, { | ||
colors: { | ||
stamp: "yellow", | ||
label: "cyan", | ||
label: true, | ||
metadata: "green" | ||
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 }); | ||
|
||
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.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); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
const path = require("path"); | ||
const twit = require("twit"); | ||
const request = require("request"); | ||
|
||
const config = require(path.join(__dirname, "config.json")); | ||
|
||
var Twitter = 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 | ||
}); | ||
|
||
console.log("Custom Twitter OCR Monitor ~ Written by Eric!"); | ||
console.log("Scanning for new tweets..."); | ||
|
||
let keywords = config.app.other.keywords; | ||
let idarray = []; | ||
|
||
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" | ||
}; | ||
|
||
function startMonitor() { | ||
/* Only way to send multiple request is by looping through the twitter names */ | ||
config.app.other.twittername.forEach(name => { | ||
Twitter.get( | ||
"statuses/user_timeline", | ||
{ | ||
screen_name: name, | ||
count: 1, | ||
exclude_replies: true, | ||
include_rts: false | ||
}, | ||
function(err, data) { | ||
if (!err) { | ||
data.forEach(function(tweet) { | ||
let text = tweet.text.toLowerCase(); | ||
let id = tweet.id_str; | ||
|
||
keywords.forEach(keyword => { | ||
if (text.includes(keyword.toLowerCase())) { | ||
if ( | ||
text.match(/restock/g) || | ||
text.match(/live/g) || | ||
text.match(/hi/g) || | ||
text.match(/test/g) | ||
) { | ||
if (!(idarray.indexOf(id) > -1)) { | ||
console.log("Found matching keyword: " + keyword + "!"); | ||
console.log("Found tweet id: " + id); | ||
|
||
/* Send Webhook */ | ||
let opts = { | ||
url: config.webhook, | ||
method: "POST", | ||
headers: headers, | ||
json: { | ||
embeds: [ | ||
{ | ||
title: `Tweet from @${tweet.user.screen_name}`, | ||
url: `https://twitter.com/${ | ||
tweet.user.name | ||
}/status/${id}`, | ||
color: 1768289, | ||
footer: { | ||
text: "Custom Twitter OCR Monitor V1" | ||
}, | ||
fields: [ | ||
{ | ||
name: "Description", | ||
value: text, | ||
inline: true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}; | ||
request(opts); | ||
console.log("Sent Hook!"); | ||
|
||
idarray.push(id); | ||
} | ||
} | ||
} else if (text.match(/[\s\S]+/g)) { | ||
// /[\s\S]+/g | ||
// /^\b\w+\b$/i | ||
// /\/\*([\s\S]*?)\*\//g | ||
|
||
if (!(idarray.indexOf(id) > -1)) { | ||
console.log("Found matching keyword: * "); | ||
console.log("Found tweet id: " + id); | ||
|
||
/* Send Webhook */ | ||
let opts = { | ||
url: config.webhook, | ||
method: "POST", | ||
headers: headers, | ||
json: { | ||
embeds: [ | ||
{ | ||
title: `Tweet from @${tweet.user.screen_name}`, | ||
url: `https://twitter.com/${ | ||
tweet.user.name | ||
}/status/${id}`, | ||
color: 1768289, | ||
footer: { | ||
text: "Custom Twitter OCR Monitor V1" | ||
}, | ||
fields: [ | ||
{ | ||
name: "Description", | ||
value: text, | ||
inline: true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}; | ||
request(opts); | ||
console.log("Sent Hook!"); | ||
|
||
idarray.push(id); | ||
} | ||
} | ||
}); | ||
}); | ||
} else { | ||
console.log( | ||
"An error occurred while attempting to search for tweets: " + | ||
err.message | ||
); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
|
||
function ocrMonitor() { | ||
/* Intelligence Twitter Bot - hehe */ | ||
} | ||
|
||
startMonitor(); | ||
setInterval(startMonitor, config.interval); | ||
} catch (err) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
} | ||
Twitter.init(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// # Logger Class | ||
// is responsible for logging the relevant information to the user | ||
|
||
// # Import Dependencies | ||
const dateFormat = require("dateformat"); | ||
const colors = require("colors/safe"); | ||
const fs = require("fs"); | ||
|
||
const Logger = function Logger(name) { | ||
this._name = name; | ||
}; | ||
|
||
Logger.prototype.green = function success(message) { | ||
console.log( | ||
`${getDateString()} [${this._name}] ` + colors.green("[+] " + message) | ||
); | ||
}; | ||
|
||
Logger.prototype.red = function error(message) { | ||
console.log( | ||
`${getDateString()} [${this._name}] ` + colors.red("[x] " + message) | ||
); | ||
}; | ||
|
||
Logger.prototype.blue = function won(message) { | ||
console.log( | ||
`${getDateString()} [${this._name}] ` + colors.blue("[$] " + message) | ||
); | ||
}; | ||
|
||
Logger.prototype.normal = function info(message) { | ||
console.log(`${getDateString()} [${this._name}] [#] ${message}`); | ||
}; | ||
|
||
Logger.prototype.yellow = function caution(message) { | ||
console.log( | ||
`${getDateString()} [${this._name}] ` + colors.yellow("[?] " + message) | ||
); | ||
}; | ||
|
||
function getDateString() { | ||
return "[" + dateFormat(new Date(), "HH:MM:ss.l") + "]"; | ||
} | ||
|
||
// export for use elsewhere | ||
module.exports = function(name) { | ||
return new Logger(name); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const request = require("request"); | ||
|
||
module.exports = function(headers, data, config) { | ||
/* Send Webhook */ | ||
let opts = { | ||
url: config.webhook, | ||
method: "POST", | ||
headers: headers, | ||
json: { | ||
embeds: [ | ||
{ | ||
title: `Tweet from @${data.user.screen_name}`, | ||
url: `https://twitter.com/${data.user.screen_name}/status/${ | ||
data.id_str | ||
}`, | ||
color: 1768289, | ||
footer: { | ||
text: `Twitter Monitor - ${data.created_at}` | ||
}, | ||
fields: [ | ||
{ | ||
name: "Description", | ||
value: data.text, | ||
inline: true | ||
} | ||
], | ||
image: { | ||
url: | ||
data.entities.media !== undefined | ||
? data.entities.media[0].media_url | ||
: null | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
|
||
request(opts); | ||
}; |
Oops, something went wrong.