Skip to content

Instantly share code, notes, and snippets.

@coleww
Last active August 29, 2015 14:26
Show Gist options
  • Save coleww/7945b601fc6f7a0e6346 to your computer and use it in GitHub Desktop.
Save coleww/7945b601fc6f7a0e6346 to your computer and use it in GitHub Desktop.
the botgle beat
var Twit = require('twit')
var T = new Twit({
consumer_key: 'blaahhh'
, consumer_secret: 'monsters'
, access_token: 'tyrannosaurus'
, access_token_secret: 'awful'
})
var shuffle = require('shuffle-array')
var options = { screen_name: 'botgle',
count: 200 };
T.get('statuses/user_timeline', options , function(err, toots) {
var now = new Date
var two_hours = 3 * 60 * 60 * 1000
var recent_toots = toots.filter(function(toot){
return now - Date.parse(toot.created_at) < two_hours
})
var played_toots = recent_toots.filter(function(toot){
return toot.text.match(/ plays /)
})
var players = played_toots.reduce(function(plyrs, toot){
var uname = toot.text.match(/@\w+/)[0].replace("@", "")
var words = toot.text.split(" ").filter(function(word){
return word.match(/^[A-Z]+$/)
})
plyrs[uname] = plyrs[uname] ? plyrs[uname].concat(words) : words
return plyrs
}, {})
var score_rows = Object.keys(players).map(function(player){
var words = shuffle(players[player]).join(" ")
if(player.length + 2 + words.length > 140){
var splits = words.split(" ")
var first = splits.slice(0, ~~(splits.length / 2)).join(" ")
var second = splits.slice(~~(splits.length / 2) ).join(" ")
return [player + ": " + first, player + ": " + second]
} else {
return player + ": " + words
}
}).reduce(function(a, b){
return a.concat(b)
}, [])
console.log(score_rows)
console.log(recent_toots.map(function(t){return t.text}))
var score_toot = recent_toots.filter(function(toot){
return toot.text.match(/ SCORES:/)
})[0]
var winner = score_toot.text.split("\n")[1].match(/@\w+/)[0].replace("@", "")
console.log(winner)
var cheers = ["CONGRATULATIONS ", "WAY TO GO ", "LETS HEAR IT FOR ", "WOW WOW WOWWWWWW "]
var salutations = ["GOOD ROUND EVERYBODY!", "LETS KEEP THAT ENERGY GOING! YEAH!", "WOOOOOOOOOOOOOO", "ALRIGHT!", "RADICAL!"]
var cheer = shuffle(cheers)[0]
var salut = shuffle(salutations)[0]
var firsty = [cheer + winner + "! " + salut]
score_rows = firsty.concat(score_rows)
score_rows.forEach(function(row, i){
setTimeout(function(){
console.log('FIRING OFF ONE')
T.post('statuses/update', { status: row }, function(err, data, response) {
console.log(data)
})
}, 1000 * 60 * (i + 1.5))
})
})
npm install --save shuffle-array twit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment