Created
July 4, 2014 07:21
-
-
Save PrototypeAlex/e087d0e1ba42d5856ed9 to your computer and use it in GitHub Desktop.
Whats on tap in Wellington
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
# Description | |
# Lists what beers are available on tap at a few of Wellington's Pubs | |
# | |
# Dependencies: | |
# "request": "^2.36.0" | |
# "lodash": "^2.4.1" | |
# | |
# Configuration: | |
# NONE | |
# | |
# Commands: | |
# hubot what's on tap at /pub/ - returns a list of beers on tap at /pub/ | |
# | |
# Notes: | |
# <optional notes required for the script> | |
# | |
# Author: | |
# <github username of the original script author> | |
request = require('request') | |
_ = require('lodash') | |
pubs = | |
'hashigo': 1 | |
'lbq': 2 | |
'vagabond': 3 | |
'greenman': 5 | |
'fork&brewer': 6 | |
'malthouse': 7 | |
'bin44': 8 | |
'd4': 9 | |
'bruhaus': 12 | |
module.exports = (robot) -> | |
robot.hear /.*(whats on tap at)(.*)/i, (msg) -> | |
pub = msg.match[2].trim() | |
unless pubs.hasOwnProperty(pub) | |
msg.send "Please select from one of the following pubs #{Object.keys(pubs).join(', ')}" | |
url = "http://maltlist.com/api/products.json?local_business_id=#{pubs[pub]}" | |
beers = [] | |
request url, (error, response, body) -> | |
if !error and response.statusCode == 200 | |
info = JSON.parse(body) | |
for beer in info.data | |
for offer in beer.offers | |
if offer.category == 'tap' | |
beers.push "#{beer.name} #{beer.abv}%" unless beer.name == 'On the Hand-pull' | |
msg.send _.unique(beers).join('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment