 module.exports = (robot) ->
   robot.brain.data.achievements ||= {}
 
-  robot.hear /(.*): *\+1 for (.*)$/i, (msg) ->
-    receiver = msg.match[1]
+  robot.hear /(.*):? *(\+1|thx) for (.*)$/i, (msg) ->
+    receiver = msg.match[1].trim()
     thanking = msg.message.user.name
-    reason   = msg.match[2]
+    reason   = msg.match[3]
 
     if receiver == thanking
       msg.send "hey, don't cheat!"


    msg.send message

  robot.hear /thx/i, (msg) ->
    msg.send "#{msg.message.user.name}: hey, grant a plus!"



  robot.respond /who thanks me??/i, (msg) ->
    user = msg.message.user.name
    response = "#{user}, #{robot.brain.data.achievements[user].length} time(s) someone thanked you:\n"
    for achievement in robot.brain.data.achievements[user]
      response += "#{achievement.given_by} for #{achievement.reason}\n"
    msg.send response
