mirror of
https://github.com/RGBCube/TwitterDiscordWebhook
synced 2025-07-27 13:07:45 +00:00
init commit
This commit is contained in:
parent
d25a1d4695
commit
87950c5d59
6 changed files with 1035 additions and 1 deletions
30
main.js
Normal file
30
main.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const Twitter = require(`twit`)
|
||||
const Webhook = require(`discord-webhook-node`)
|
||||
const config = require(`./config/config.json`)
|
||||
|
||||
const wClient = new Webhook.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}`
|
||||
})
|
||||
|
||||
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}`);
|
||||
})
|
||||
|
||||
var stream = tClient.stream('statuses/filter', { follow: `${config.user_id}` })
|
||||
console.log(`Fetching tweets from id: ${config.user_id}`)
|
||||
|
||||
stream.on('tweet', function (tweet) {
|
||||
let twitterLink = `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`
|
||||
wClient.send(`${config.webhook_message} ${twitterLink}`)
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue