mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-02 11:58:10 -05:00
Fixed #1356.
This commit is contained in:
parent
a8644d030e
commit
4d24233b0d
1 changed files with 19 additions and 16 deletions
|
@ -548,8 +548,8 @@ isRequestFromDesignatedCronHandler = (req, res) ->
|
||||||
|
|
||||||
handleLadderUpdate = (req, res) ->
|
handleLadderUpdate = (req, res) ->
|
||||||
log.info('Going to see about sending ladder update emails.')
|
log.info('Going to see about sending ladder update emails.')
|
||||||
requestIsFromDesignatedCronHandler = isRequestFromDesignatedCronHandler req, res
|
requestIsFromDesignatedCronHandler = DEBUGGING or isRequestFromDesignatedCronHandler req, res
|
||||||
return unless requestIsFromDesignatedCronHandler or DEBUGGING
|
return unless requestIsFromDesignatedCronHandler
|
||||||
|
|
||||||
res.send('Great work, Captain Cron! I can take it from here.')
|
res.send('Great work, Captain Cron! I can take it from here.')
|
||||||
res.end()
|
res.end()
|
||||||
|
@ -564,7 +564,7 @@ handleLadderUpdate = (req, res) ->
|
||||||
endTime = startTime + 15 * 60 * 1000 # Debugging: make sure there's something to send
|
endTime = startTime + 15 * 60 * 1000 # Debugging: make sure there's something to send
|
||||||
findParameters = {submitted: true, submitDate: {$gt: new Date(startTime), $lte: new Date(endTime)}}
|
findParameters = {submitted: true, submitDate: {$gt: new Date(startTime), $lte: new Date(endTime)}}
|
||||||
# TODO: think about putting screenshots in the email
|
# TODO: think about putting screenshots in the email
|
||||||
selectString = 'creator team levelName levelID totalScore matches submitted submitDate scoreHistory'
|
selectString = 'creator team levelName levelID totalScore matches submitted submitDate scoreHistory level.original'
|
||||||
query = LevelSession.find(findParameters)
|
query = LevelSession.find(findParameters)
|
||||||
.select(selectString)
|
.select(selectString)
|
||||||
.lean()
|
.lean()
|
||||||
|
@ -600,7 +600,7 @@ sendLadderUpdateEmail = (session, now, daysAgo) ->
|
||||||
defeat = _.last defeats
|
defeat = _.last defeats
|
||||||
victory = _.last victories
|
victory = _.last victories
|
||||||
|
|
||||||
sendEmail = (defeatContext, victoryContext) ->
|
sendEmail = (defeatContext, victoryContext, levelVersionsContext) ->
|
||||||
# TODO: do something with the preferredLanguage?
|
# TODO: do something with the preferredLanguage?
|
||||||
context =
|
context =
|
||||||
email_id: sendwithus.templates.ladder_update_email
|
email_id: sendwithus.templates.ladder_update_email
|
||||||
|
@ -621,6 +621,7 @@ sendLadderUpdateEmail = (session, now, daysAgo) ->
|
||||||
score_history_graph_url: getScoreHistoryGraphURL session, daysAgo
|
score_history_graph_url: getScoreHistoryGraphURL session, daysAgo
|
||||||
defeat: defeatContext
|
defeat: defeatContext
|
||||||
victory: victoryContext
|
victory: victoryContext
|
||||||
|
levelVersions: levelVersionsContext
|
||||||
log.info "Sending ladder update email to #{context.recipient.address} with #{context.email_data.wins} wins and #{context.email_data.losses} losses since #{daysAgo} day(s) ago."
|
log.info "Sending ladder update email to #{context.recipient.address} with #{context.email_data.wins} wins and #{context.email_data.losses} losses since #{daysAgo} day(s) ago."
|
||||||
sendwithus.api.send context, (err, result) ->
|
sendwithus.api.send context, (err, result) ->
|
||||||
log.error "Error sending ladder update email: #{err} with result #{result}" if err
|
log.error "Error sending ladder update email: #{err} with result #{result}" if err
|
||||||
|
@ -639,7 +640,9 @@ sendLadderUpdateEmail = (session, now, daysAgo) ->
|
||||||
log.error "Couldn't find victorious opponent: #{err}"
|
log.error "Couldn't find victorious opponent: #{err}"
|
||||||
victoriousOpponent = null
|
victoriousOpponent = null
|
||||||
defeatContext = {opponent_name: victoriousOpponent?.name ? 'Anoner', url: urlForMatch(defeat)} if defeat
|
defeatContext = {opponent_name: victoriousOpponent?.name ? 'Anoner', url: urlForMatch(defeat)} if defeat
|
||||||
sendEmail defeatContext, victoryContext
|
|
||||||
|
Level.find({original: session.level.original, created: {$gt: session.submitDate}}).select('created commitMessage version').sort('-created').lean().exec (err, levelVersions) ->
|
||||||
|
sendEmail defeatContext, victoryContext, (if levelVersions.length then levelVersions else null)
|
||||||
|
|
||||||
if defeat
|
if defeat
|
||||||
User.findOne({_id: defeat.opponents[0].userID}).select('name').lean().exec onFetchedVictoriousOpponent
|
User.findOne({_id: defeat.opponents[0].userID}).select('name').lean().exec onFetchedVictoriousOpponent
|
||||||
|
|
Loading…
Reference in a new issue