Skip to content

Instantly share code, notes, and snippets.

@JerrySievert
Created May 14, 2014 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JerrySievert/4494d893574c78bec9ba to your computer and use it in GitHub Desktop.
Save JerrySievert/4494d893574c78bec9ba to your computer and use it in GitHub Desktop.
function(msg) {
if(/^baileys/.test(msg.message)) {
var match = msg.message.match(/^baileys\s+(.+)/);
var tap;
var taps = [ ];
json = http.get("http://api.legitimatesounding.com/api/baileys");
feed = JSON.parse(json);
var tap_list = "Bailey's Taps: ";
if (match && feed.data[match[1]]) {
tap = feed.data[match[1]];
return tap_list + "Tap " + match[1] + " - " + tap.brewery + " / " + tap.beer + " (" + tap.prices.join(", ") + ") " + parseInt(tap.fill*100) + "% full, served in a " + tap.glass + " glass";
} else {
for(var tap_id in feed.data) {
tap = feed.data[tap_id];
if (match) {
if (tap.beer.toUpperCase().match(match[1].toUpperCase()) || tap.brewery.toUpperCase().match(match[1].toUpperCase()) || tap.glass.toUpperCase().match(match[1].toUpperCase()) || tap.style.toUpperCase().match(match[1].toUpperCase())) {
taps.push("Tap " + tap_id + " - " + tap.brewery + " / " + tap.beer + " (" + tap.prices.join(", ") + ") " + parseInt(tap.fill*100) + "% full, served in a " + tap.glass + " glass");
}
} else {
taps.push(tap_id + "-" + tap.beer);
}
}
}
if (taps.length === 0) {
tap_list += " none found";
} else {
tap_list += taps.join(", ");
}
return tap_list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment