Created
January 4, 2012 01:32
-
-
Save jtrim/1557973 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Gets the last gist for specified user | |
| # | |
| # last gist [for] <username> - Returns the last gist for specified user | |
| module.exports = (robot) -> | |
| robot.respond /last gist (?:for)? (.+)/i, (msg) -> | |
| username = msg.match[1] | |
| url = "https://api.github.com/users/#{username}/gists" | |
| msg.http(url).get() (err, res, body) -> | |
| gists = JSON.parse(body) | |
| indexed = {} | |
| dates = [] | |
| indexed[+new Date(gist.created_at)] = gist for gist in gists when gist.public == true | |
| dates.push(+new Date(gist.created_at)) for gist in gists | |
| gist = indexed[Math.max.apply(global, dates)] | |
| msg.send "Last public gist by #{username}:" | |
| msg.send gist.html_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment