Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Created September 4, 2012 23:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save donpdonp/3628025 to your computer and use it in GitHub Desktop.
Save donpdonp/3628025 to your computer and use it in GitHub Desktop.
taplist
function(msg) {
var cmd = /^taplist ?(.*)?/
var match = cmd.exec(msg.message)
if(match) {
var filter = match[1]
json = http.get("http://ec2-50-112-236-55.us-west-2.compute.amazonaws.com/api/baileys")
feed = JSON.parse(json)
var tap_list = "Bailey's: ";
var taps = [];
for(var tap_id in feed.data) {
var tap = feed.data[tap_id]
var good;
if (filter) {
good = false;
var filterx = new RegExp(filter,"i")
if(filterx.exec(tap.brewery)) { good = true }
if(filterx.exec(tap.beer)) { good = true }
} else {
good = true;
}
if(good){
if(filter) {
taps.push(tap.brewery+"/"+tap.beer+" "+tap.prices[0]+" "+parseInt(tap.fill*100)+"%")
} else {
taps.push(tap.beer)
}
}
}
if(taps.length >= 1) {
tap_list = tap_list + "("+taps.length+") "+taps.join(', ')
}
if(taps.length == 0) {
tap_list = tap_list + "nothing."
}
return tap_list;
}
}
@JerrySievert
Copy link

function(msg) {
if(/^taplist/.test(msg.message)) {
var match = msg.message.match(/^taplist\s+(\w+)/);

json = http.get("http://ec2-50-112-236-55.us-west-2.compute.amazonaws.com/api/baileys");
feed = JSON.parse(json);
var tap_list = "Bailey's: ";

if (match && feed.data[match[1]]) {
  var tap = feed.data[match[1]];
  tap_list = tap_list + match[1] + ": " + tap.brewery + " / " + tap.beer + " (" + tap.prices.join(", ") + "), " + parseInt(tap.fill*100) + "%";
} else {
  for(var tap_id in feed.data) {
    var tap = feed.data[tap_id];
    tap_list = tap_list + " "+tap.brewery+"/"+tap.beer+" "+tap.prices[0]+" "+parseInt(tap.fill*100)+"%, ";
  }
}
return tap_list;

}
}

@JerrySievert
Copy link

function(msg) {
  if(/^taplist/.test(msg.message)) {
    var match = msg.message.match(/^taplist\s+(\w+)/);

    json = http.get("http://ec2-50-112-236-55.us-west-2.compute.amazonaws.com/api/baileys");
    feed = JSON.parse(json);
    var tap_list = "Bailey's: ";

    if (match && feed.data[match[1]]) {
      var tap = feed.data[match[1]];
      tap_list = tap_list + match[1] + ": " + tap.brewery + " / " + tap.beer + " (" + tap.prices.join(", ") + "), " + parseInt(tap.fill*100) + "%";
    } else {
      for(var tap_id in feed.data) {
        var tap = feed.data[tap_id];
        tap_list = tap_list + " "+tap.brewery+"/"+tap.beer+" "+tap.prices[0]+" "+parseInt(tap.fill*100)+"%, ";
      }
    }
    return tap_list;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment