diff --git a/main.js b/main.js index f331185..782466e 100644 --- a/main.js +++ b/main.js @@ -1,47 +1,50 @@ -const Twitter = require(`twit`) -const Webhook = require(`discord-webhook-node`) -const config = require(`./config/config.json`) +import Twitter from "twit"; +import { Webhook } from "discord-webhook-node"; -const wClient = new Webhook.Webhook(`${config.webhook_url}`) -wClient.setAvatar(`${config.webhook_avatar}`) -wClient.setUsername(`${config.webhook_name}`) +const config = require("config.json"); + +const wClient = new Webhook(config.webhook_url); +wClient.setAvatar(config.webhook_avatar); +wClient.setUsername(config.webhook_name); const tClient = new Twitter({ - consumer_key: `${config.api_key}`, - consumer_secret: `${config.api_secret}`, - access_token: `${config.access_token}`, - access_token_secret: `${config.acesss_secret}` -}) + consumer_key: config.api_key, + consumer_secret: config.api_secret, + access_token: config.access_token, + access_token_secret: config.acesss_secret, +}); -tClient.get('account/verify_credentials', { skip_status: true }) -.catch(function (err) { - console.log(`Unable to login due to: ${err}`) -}) -.then(function (result) { - console.log(`Logged in as: ${result.data.name}`); -}) +tClient.get("account/verify_credentials", { skip_status: true }) + .catch(err => { + console.log(`Unable to login due to the following error:\n${err}`) + }) + .then(res => { + console.log(`Logged in as '${res.data.name}'!`); + }); -var stream = tClient.stream('statuses/filter', { follow: `${config.user_id}` }) -console.log(`Fetching tweets from id: ${config.user_id}`) +let stream = tClient.stream("statuses/filter", { follow: config.user_id }); -stream.on('connected', function (response) { - console.log(`Connected to twitter`) -}) +console.log(`Fetching tweets from id '${config.user_id}'.`); -stream.on('tweet', function (tweet) { - if(tweet.retweeted_status || tweet.in_reply_to_status_id || tweet.is_quote_status) return - let twitterLink = `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}` - wClient.send(`${config.webhook_message} ${twitterLink}`) - }) +stream.on("connected", _ => { + console.log("Successfully connected to Twitter!"); +}); + +stream.on("tweet", twt => { + if(twt.retweeted_status || twt.in_reply_to_status_id || twt.is_quote_status) return; + + let twitterLink = `https://twitter.com/${twt.user.screen_name}/status/${twt.id_str}`; + wClient.send(`${config.webhook_message} ${twitterLink}`); +}); -stream.on('disconnect', function (disconnectMessage) { - console.log(`Disconnected from twitter`) -}) +stream.on("disconnect", _ => { + console.log("Disconnected from twitter!"); +}); -stream.on('reconnect', function (request, response, connectInterval) { - console.log(`reconnecting to twitter`) -}) +stream.on("reconnect", function (_, _, _) => { + console.log("Reconnecting to Twitter!"); +}); -process.on('uncaughtException', function (err) { - console.log("something happened!", err); -}); \ No newline at end of file +process.on("uncaughtException", err => { + console.log(`Something (bad) happened: ${err}`); +});