 
 #semi-mute
 #if (msg.random([0..10]) < 3)
+
+report_kill = (robot, msg, kill) ->
+  name_for_id(robot, msg, kill.victim.shipTypeID, (msg, ship) ->
+    msg.send "#{kill.victim.characterName} died last in a #{ship}" # + " https://beta.eve-kill.net/kill/#{kill.killID}" 
+  )
+
+name_for_id = (robot, msg, id, callback) ->
+  name = robot.brain.get "itemID.#{id}"
+  if name?
+    callback(msg, name)
+  else
+    msg.http("https://api.eveonline.com/Eve/TypeName.xml.aspx?ids=#{id}")
+      .get() (err2, res2, xml) ->
+        if res2.statusCode isnt 200 or err2
+          return '<unknown: #{id}>'
+        tree = JSON.parse(parser.toJson(xml))
+        robot.brain.set "itemID.#{id}", tree.eveapi.result.rowset.row.typeName
+        callback(msg, tree.eveapi.result.rowset.row.typeName)
 
 awake = (robot) ->
   wake = robot.brain.get 'sleepUntil' 

parser = require('xml2json')
zlib = require('zlib')
moment = require('moment')

module.exports = (robot) ->
  robot.respond /(kills|losses)/i, (msg) ->
    if !corp_id?
      msg.send "I can't do that. Someone forgot to tell me the corporation ID you care about."
      return
    
    msg.send "Give me a moment..."
    data = ""
    # TODO Number of hours should be from ENV
    msg.http("https://zkillboard.com/api/#{msg.match[1]}/corporationID/#{corp_id}/pastSeconds/108000/")
      .headers('Accept': 'application/json', 'Accept-Encoding': 'gzip', 'User-Agent': "OscarRobo/#{version} [#{email}] (on Hubot/2.9.0)")
      .get( (err, req) ->
        req.addListener "response", (res)->

    if (awake(robot)) 
      msg.send "http://imagemacros.files.wordpress.com/2010/02/roger_american_dad_technical_problems.png"

  robot.respond /stfu|shut up|mute|sleep|diaf/i, (msg) ->
    wake = moment().add(15, 'm')
    robot.brain.set 'sleepUntil', wake
    msg.send "Do you want me to sit in a corner and rust or just fall apart where I'm standing?"
