Created
September 4, 2012 23:27
-
-
Save donpdonp/3628025 to your computer and use it in GitHub Desktop.
taplist
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
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; | |
} | |
} |
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
function(msg) {
if(/^taplist/.test(msg.message)) {
var match = msg.message.match(/^taplist\s+(\w+)/);
}
}