Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions scripts/cute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think random exists here. You set it in a for loop in a different function (line 39), on a scope we don't have access to here.

});

});
Expand All @@ -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);
}
}
});
});
Expand Down
40 changes: 31 additions & 9 deletions scripts/garage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -41,17 +49,31 @@ 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:")
percent = parseInt(line.replace("percent:", ''))
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()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now we have two different places where we do the same thing (get pubsub stuff) it would probably be best to have a function somewhere else that is used both here and in scripts/pubsub.js.

Buuut we may want to hold off this specific change until we deal with #24

robot.brain.set('pubsubCheckDate', (new Date()).toDateString())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more a matter of opinion, but wouldn't it be better to assign today's date to a variable instead of calling (new Date()).toDateString() twice? It's not a performance thing tho, more a readability thing.

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