|
| 1 | +util = require 'util' |
| 2 | +app = require '../config/app' |
| 3 | +Team = app.db.model 'Team' |
| 4 | + |
| 5 | +message = -> |
| 6 | + messages = [ |
| 7 | + 'psst, a judge is checking out your app' |
| 8 | + 'your page is being attacked, erm judged' |
| 9 | + 'batten down the hatches, a judge is coming' |
| 10 | + 'come quick! a judge is on the way' |
| 11 | + 'the judge has entered the building, erm your app' |
| 12 | + 'come and play, you\'re being judged' |
| 13 | + 'judge dread? oh noes! your app is being judged' |
| 14 | + ] |
| 15 | + messages[Math.floor(Math.random() * messages.length)] |
| 16 | + |
| 17 | +# notify teams when a judge visits |
| 18 | +app.post '/notify', (req, res, next) -> |
| 19 | + # only notify when judges click through |
| 20 | + return res.send(200) unless req.user?.judge |
| 21 | + |
| 22 | + # see if the url being clicked belongs to a team entry |
| 23 | + url = req.body.url |
| 24 | + Team.findOne 'entry.url': req.body.url, (err, team) -> |
| 25 | + return next(err) if err |
| 26 | + |
| 27 | + # if the url doesn't belong to team, or the team is does not have alerts |
| 28 | + # enabled, just ignore it |
| 29 | + return res.send(200) unless team?.entry?.alert |
| 30 | + |
| 31 | + # load the twitter handles for the team |
| 32 | + team.twitterScreenNames (err, handles) -> |
| 33 | + return next(err) if err |
| 34 | + |
| 35 | + util.log("NOTIFY #{team} (#{handles.join(', ')})".magenta) |
| 36 | + |
| 37 | + # DM the team with the message |
| 38 | + |
| 39 | + app.twitter.dm handles, "#{message()} - join at #{url}", (err, result) -> |
| 40 | + return next(err) if err |
| 41 | + |
| 42 | + console.dir(result) |
| 43 | + res.send(200) |
| 44 | + |
0 commit comments