     process.env.HUBOT_BASE_URL + path.join(robot.name, 'logs', room.slice(1))
 
   logMessageES: (log, room, msg) ->
-    if !missingEnvironmentForApi(msg)
-      if room in logRooms
+    unless missingEnvironmentForApi(msg)
+      if room in @logRooms
         date = moment.utc()
         log['@timestamp'] = date.format()
         json = JSON.stringify(log)
 
-        index = logIndexName
+        index = @logIndexName
         index = index + '-' + date.format('YYYY.MM.DD')
 
-        msg.http(logESUrl)
+        @robot.http(@logESUrl)
           .path(index + '/irclog/')
           .post(json) (err, res, body) ->
             if res.statusCode > 299
-              robot.logger.warning res.statusCode
-              robot.logger.warning body
+              @robot.logger.warning res.statusCode
+              @robot.logger.warning body
 
 
 

        <h1>#{title}</h1>
    """

  foot_html = (url) ->
    "<div class=\"foot\">More Power on <a href=\"#{url}\">#{url}</a></div></body></html>"

  escape = (message) ->
    return message.replace(/&/g, '&amp;')
      .replace(/</g, '&lt;')
      .replace(/>/g, '&gt;')

      size: 1000
    }
    json = JSON.stringify(query)
    index = @logIndexName + '-' + start.format('YYYY.MM.DD')
    index_end = @logIndexName + '-' + stop.format('YYYY.MM.DD')
    if index == index_end
      @searchES index, json, (body) ->
        cb body.hits.hits
    else
      @searchES index, json, (body) ->
        @searchES index_end, json, (body_end) ->
          cb body.hits.hits.concat(body_end.hits.hits)

  getLastTerm: (room, term, cb) ->
    query = {
      query: {
        bool: {
