diff --git a/app/lib/AudioPlayer.coffee b/app/lib/AudioPlayer.coffee index 8f752a226..8f71d50e2 100644 --- a/app/lib/AudioPlayer.coffee +++ b/app/lib/AudioPlayer.coffee @@ -88,6 +88,7 @@ class AudioPlayer extends CocoClass @soundsToPlayWhenLoaded[name] = volume playSound: (name, volume=1, delay=0, pos=null) -> + return console.error 'Trying to play empty sound?' unless name audioOptions = {volume: (me.get('volume') ? 1) * volume, delay: delay} filename = if _.string.startsWith(name, '/file/') then name else '/file/' + name unless (filename of cache) and createjs.Sound.loadComplete filename diff --git a/server/hipchat.coffee b/server/hipchat.coffee new file mode 100644 index 000000000..6ca43205d --- /dev/null +++ b/server/hipchat.coffee @@ -0,0 +1,16 @@ +config = require '../server_config' +request = require 'request' +log = require 'winston' + +module.exports.sendHipChatMessage = sendHipChatMessage = (message) -> + return unless key = config.hipchatAPIKey + roomID = 254598 + form = + color: 'yellow' + notify: false + message: message + messageFormat: 'html' + url = "https://api.hipchat.com/v2/room/#{roomID}/notification?auth_token=#{key}" + request.post {uri: url, json: form}, (err, res, body) -> + return log.error 'Error sending HipChat patch request:', err or body if err or /error/.test body + #log.info "Got HipChat patch response:", body diff --git a/server/patches/patch_handler.coffee b/server/patches/patch_handler.coffee index 12f34127b..fd316ce4b 100644 --- a/server/patches/patch_handler.coffee +++ b/server/patches/patch_handler.coffee @@ -6,6 +6,7 @@ schema = require '../../app/schemas/models/patch' mongoose = require 'mongoose' log = require 'winston' sendwithus = require '../sendwithus' +hipchat = require '../hipchat' PatchHandler = class PatchHandler extends Handler modelClass: Patch @@ -75,14 +76,16 @@ PatchHandler = class PatchHandler extends Handler onPostSuccess: (req, doc) -> log.error 'Error sending patch created: could not find the loaded target on the patch object.' unless doc.targetLoaded return unless doc.targetLoaded + docLink = "http://codecombat.com#{req.headers['x-current-path']}" + @sendPatchCreatedHipChatMessage creator: req.user, patch: doc, target: doc.targetLoaded, docLink: docLink watchers = doc.targetLoaded.get('watchers') or [] watchers = (w for w in watchers when not w.equals(req.user.get('_id'))) return unless watchers?.length User.find({_id: {$in: watchers}}).select({email: 1, name: 1}).exec (err, watchers) => for watcher in watchers - @sendPatchCreatedEmail req.user, watcher, doc, doc.targetLoaded, req.headers['x-current-path'] + @sendPatchCreatedEmail req.user, watcher, doc, doc.targetLoaded, docLink - sendPatchCreatedEmail: (patchCreator, watcher, patch, target, editPath) -> + sendPatchCreatedEmail: (patchCreator, watcher, patch, target, docLink) -> # return if watcher._id is patchCreator._id context = email_id: sendwithus.templates.patch_created @@ -92,8 +95,12 @@ PatchHandler = class PatchHandler extends Handler email_data: doc_name: target.get('name') or '???' submitter_name: patchCreator.get('name') or '???' - doc_link: "http://codecombat.com#{editPath}" + doc_link: docLink commit_message: patch.get('commitMessage') sendwithus.api.send context, (err, result) -> + sendPatchCreatedHipChatMessage: (options) -> + message = "#{options.creator.get('name')} submitted a patch to #{options.target.get('name')}: #{options.patch.get('commitMessage')}" + hipchat.sendHipChatMessage message + module.exports = new PatchHandler() diff --git a/server_config.coffee b/server_config.coffee index ff2a9cfcd..f6ff811ad 100644 --- a/server_config.coffee +++ b/server_config.coffee @@ -41,6 +41,8 @@ config.mail = cronHandlerPublicIP: process.env.COCO_CRON_PUBLIC_IP or '' cronHandlerPrivateIP: process.env.COCO_CRON_PRIVATE_IP or '' +config.hipchatAPIKey = process.env.COCO_HIPCHAT_API_KEY or '' + config.queue = accessKeyId: process.env.COCO_AWS_ACCESS_KEY_ID or '' secretAccessKey: process.env.COCO_AWS_SECRET_ACCESS_KEY or ''