mirror of
https://github.com/RGBCube/TwitterDiscordWebhook
synced 2025-07-27 13:07:45 +00:00
Modernize main.js
This commit is contained in:
parent
5ae7096e4a
commit
7343795ee6
1 changed files with 40 additions and 37 deletions
89
main.js
89
main.js
|
@ -1,47 +1,50 @@
|
||||||
const Twitter = require(`twit`)
|
import Twitter from "twit";
|
||||||
const Webhook = require(`discord-webhook-node`)
|
import { Webhook } from "discord-webhook-node";
|
||||||
const config = require(`./config/config.json`)
|
|
||||||
|
|
||||||
const wClient = new Webhook.Webhook(`${config.webhook_url}`)
|
const config = require("config.json");
|
||||||
wClient.setAvatar(`${config.webhook_avatar}`)
|
|
||||||
wClient.setUsername(`${config.webhook_name}`)
|
const wClient = new Webhook(config.webhook_url);
|
||||||
|
wClient.setAvatar(config.webhook_avatar);
|
||||||
|
wClient.setUsername(config.webhook_name);
|
||||||
|
|
||||||
const tClient = new Twitter({
|
const tClient = new Twitter({
|
||||||
consumer_key: `${config.api_key}`,
|
consumer_key: config.api_key,
|
||||||
consumer_secret: `${config.api_secret}`,
|
consumer_secret: config.api_secret,
|
||||||
access_token: `${config.access_token}`,
|
access_token: config.access_token,
|
||||||
access_token_secret: `${config.acesss_secret}`
|
access_token_secret: config.acesss_secret,
|
||||||
})
|
});
|
||||||
|
|
||||||
tClient.get('account/verify_credentials', { skip_status: true })
|
tClient.get("account/verify_credentials", { skip_status: true })
|
||||||
.catch(function (err) {
|
.catch(err => {
|
||||||
console.log(`Unable to login due to: ${err}`)
|
console.log(`Unable to login due to the following error:\n${err}`)
|
||||||
})
|
})
|
||||||
.then(function (result) {
|
.then(res => {
|
||||||
console.log(`Logged in as: ${result.data.name}`);
|
console.log(`Logged in as '${res.data.name}'!`);
|
||||||
})
|
});
|
||||||
|
|
||||||
var stream = tClient.stream('statuses/filter', { follow: `${config.user_id}` })
|
let stream = tClient.stream("statuses/filter", { follow: config.user_id });
|
||||||
console.log(`Fetching tweets from id: ${config.user_id}`)
|
|
||||||
|
console.log(`Fetching tweets from id '${config.user_id}'.`);
|
||||||
stream.on('connected', function (response) {
|
|
||||||
console.log(`Connected to twitter`)
|
stream.on("connected", _ => {
|
||||||
})
|
console.log("Successfully connected to Twitter!");
|
||||||
|
});
|
||||||
stream.on('tweet', function (tweet) {
|
|
||||||
if(tweet.retweeted_status || tweet.in_reply_to_status_id || tweet.is_quote_status) return
|
stream.on("tweet", twt => {
|
||||||
let twitterLink = `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`
|
if(twt.retweeted_status || twt.in_reply_to_status_id || twt.is_quote_status) return;
|
||||||
wClient.send(`${config.webhook_message} ${twitterLink}`)
|
|
||||||
})
|
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);
|
|
||||||
|
process.on("uncaughtException", err => {
|
||||||
|
console.log(`Something (bad) happened: ${err}`);
|
||||||
});
|
});
|
Loading…
Add table
Add a link
Reference in a new issue