diff --git a/scripts/cute.js b/scripts/cute.js index 428fbe9..a00b3c4 100644 --- a/scripts/cute.js +++ b/scripts/cute.js @@ -2,7 +2,6 @@ // Cute bomb is the cutest script //Commands: // fred cute me -// fred cute bomb // fred cute bomb N module.exports = function(robot){ @@ -15,7 +14,9 @@ module.exports = function(robot){ return; } - msg.send( (JSON.parse(body).data.children)[Math.floor(Math.random()*(JSON.parse(body).data.children).length)].data.url); + var json = JSON.parse(body).data.children; + + msg.send( json[random].data.url); }); }); @@ -31,8 +32,15 @@ module.exports = function(robot){ return; } + var json = JSON.parse(body).data.children; + + for(var i = 0; i < count; i++){ - msg.send( (JSON.parse(body).data.children)[Math.floor(Math.random()*(JSON.parse(body).data.children).length)].data.url); + var random = Math.floor(Math.random()*json.length); + msg.send( json[random].data.url); + if(json.length > 1){ + json.splice(random, 1); + } } }); }); diff --git a/scripts/garage.coffee b/scripts/garage.coffee index bcb48bd..0e99e2f 100644 --- a/scripts/garage.coffee +++ b/scripts/garage.coffee @@ -22,13 +22,21 @@ module.exports = (robot) -> if garage.garage.toLowerCase() is msg.match[2].toLowerCase() msg.send("Garage " + garage.garage + " is " + garage.perc + "% full") - robot.respond /garage/i, (msg)-> - getGarages (garages) -> + robot.respond /garage$/i, (msg)-> + getGarages (garages, pubsub) -> response = "" + smallest = 100 for garage in garages + if garage.perc < smallest and garage.garage != 'Libra' + smallest = garage.perc response += "Garage #{garage.garage} #{garage.perc}%\n" + if smallest > 90 + response += "http://i.imgur.com/OXlUFE1.jpg\n" + if pubsub + response += "But hey, Chicken Tender Subs are on sale! | www.arepublixchickentendersubsonsale.com" + msg.send(response) - + robot.respond /where should I park?/i, (msg)-> getGarages (garages) -> smallestGarage = {garage: "THEY'RE ALL FULL", perc: 100}; @@ -41,9 +49,10 @@ module.exports = (robot) -> getGarages = (callback) -> r = request 'https://secure.parking.ucf.edu/GarageCount/iframe.aspx/', (error, response, body) -> garages = [] - $ = cheerio.load(body); + pubsub = false; + $ = cheerio.load(body) $('.dxgvDataRow_DevEx').each (i, obj) -> - thisGarage = {}; + thisGarage = {} html = $(obj).html().replace(RegExp(' ', 'g'), '').split '\n' for line in html if line.startsWith("percent:") @@ -51,7 +60,20 @@ module.exports = (robot) -> thisGarage.perc = percent thisGarage.garage = ($(obj).find('.dxgv').html()).replace("Garage ", '') garages[i] = thisGarage - callback garages - return null - - + + if robot.brain.get('pubsubCheckDate') isnt (new Date()).toDateString() + robot.brain.set('pubsubCheckDate', (new Date()).toDateString()) + r2 = request 'http://www.arepublixchickentendersubsonsale.com/', (error2, response2, body2) -> + $ = cheerio.load(body2); + if $.html().includes("onsale:yes") + robot.brain.set('pubsub', 'true') + pubsub = true + else + pubsub = false + callback garages, pubsub + return null + else + if robot.brain.get('pubsub') is 'true' + pubsub = true + callback garages, pubsub + return null \ No newline at end of file