Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
reply to user
Browse files Browse the repository at this point in the history
  • Loading branch information
spences10 committed May 29, 2017
1 parent 9555b53 commit dffad45
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
36 changes: 36 additions & 0 deletions src/api/reply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const Twit = require('twit')
const unique = require('unique-random-array')
const config = require('../config')

const param = config.twitterConfig
const randomReply = unique(param.randomReply.split(','))

const bot = new Twit(config.twitterKeys)

// function: tweets back to user who followed
function tweetNow(text) {
let tweet = {
status: text
}

bot.post('statuses/update', tweet, (err, data, response) => {
if (err) {
console.log('ERRORDERP Reply', err)
}
console.log('SUCCESS: Replied: ', text)
})
}

// function: replies to user who followed
const reply = (event) => {
// get user's twitter handler/screen name
let screenName = event.source.screen_name

const response = randomReply()

const res = response.replace('${screenName}', screenName);

tweetNow(res)
}

module.exports = reply
5 changes: 3 additions & 2 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const config = require('./config')
const bot = new Twit(config.twitterKeys)

const retweet = require('./api/retweet')
const reply = require('./api/reply')

// retweet on keywords
retweet()
setInterval(retweet, config.twitterConfig.retweet)

// reply to new follower


const userStream = bot.stream('user')
userStream.on('follow', reply)
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = {
retweet: process.env.TWITTER_RETWEET_RATE * 1000 * 60,
like: process.env.TWITTER_LIKE_RATE * 1000 * 60,
quote: process.env.TWITTER_QUOTE_RATE * 1000 * 60,
searchCount: process.env.TWITTER_SEARCH_COUNT
searchCount: process.env.TWITTER_SEARCH_COUNT,
randomReply: process.env.RANDOM_REPLY
},
sentiment_api_key: process.env.SENTIMENT_KEY
}

0 comments on commit dffad45

Please sign in to comment.