Skip to content

Commit

Permalink
RT functionality 🐤🐥
Browse files Browse the repository at this point in the history
  • Loading branch information
spences10 committed May 17, 2017
1 parent 76b573e commit e43174e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
TODO:
- [ ] Follow the community hashtag and retweet tweets to it
- [ ] Welcome new community members summarising their skills and who they'd like to pair with
- [ ] Retweet specific keywords "pair programming", "anyone want to pair with me"
- [x] Retweet specific keywords "pair programming", "anyone want to pair with me"
- [ ] Reply to those specific keywords promoting PairHub


34 changes: 34 additions & 0 deletions src/api/retweet.js
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
15 changes: 5 additions & 10 deletions src/bot.js
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)
17 changes: 13 additions & 4 deletions src/config.js
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
}
}

0 comments on commit e43174e

Please sign in to comment.