-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
53 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const Twit = require('twit') | ||
const unique = require('unique-random-array') | ||
const config = require('../config') | ||
|
||
const param = config.twitterConfig | ||
const queryString = unique(param.queryString.split(',')) | ||
|
||
const bot = new Twit(config.twitterKeys) | ||
|
||
const retweet = () => { | ||
let query = queryString() | ||
bot.get('search/tweets', { | ||
q: query, | ||
result_type: param.resultType, | ||
lang: param.language, | ||
filter: 'safe' | ||
}, (err, data) => { | ||
// grab tweet ID to retweet | ||
let retweetId = data.statuses[0].id_str | ||
|
||
if (err) console.log('ERRORDERP: Cannot Search Tweet!') | ||
|
||
bot.post('statuses/retweet/:id', { | ||
id: retweetId | ||
}, (err, response) => { | ||
if (err) { | ||
console.log('ERRORDERP: Retweet!') | ||
} | ||
console.log(data.statuses[0].text, 'SUCCESS: RT') | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = retweet |
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,14 +1,9 @@ | ||
const Twit = require('twit') | ||
const config = require('./config') | ||
|
||
const bot = new Twit(config) | ||
const bot = new Twit(config.twitterKeys) | ||
|
||
bot.post('statuses/update', { | ||
status: 'hello world!' | ||
}, (err, data, response) => { | ||
if (err) { | ||
console.log(err) | ||
} else { | ||
console.log(`${data.text} tweeted!`) | ||
} | ||
}) | ||
const retweet = require('./api/retweet') | ||
|
||
retweet() | ||
setInterval(retweet, config.twitterConfig.retweet) |
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,8 +1,17 @@ | ||
require('dotenv').config() | ||
|
||
module.exports = { | ||
consumer_key: process.env.CONSUMER_KEY, | ||
consumer_secret: process.env.CONSUMER_SECRET, | ||
access_token: process.env.ACCESS_TOKEN, | ||
access_token_secret: process.env.ACCESS_TOKEN_SECRET, | ||
twitterKeys: { | ||
consumer_key: process.env.CONSUMER_KEY, | ||
consumer_secret: process.env.CONSUMER_SECRET, | ||
access_token: process.env.ACCESS_TOKEN, | ||
access_token_secret: process.env.ACCESS_TOKEN_SECRET | ||
}, | ||
twitterConfig: { | ||
queryString: process.env.QUERY_STRING, | ||
resultType: process.env.RESULT_TYPE, | ||
language: process.env.LANG, | ||
username: process.env.TWITTER_USERNAME, | ||
retweet: process.env.TWITTER_RETWEET_RATE * 1000 * 60 | ||
} | ||
} |