 
     bot.addListener 'message', (from, to, message) ->
       console.log "From #{from} to #{to}: #{message}"
-      
-      user = self.userForName from
-      unless user?
-        id = (new Date().getTime() / 1000).toString().replace('.','')
-        user = self.userForId id
-        user.name = from
 
-      if to.match(/^[&#]/)
-        user.room = to
+      user = self.createUser to, from
+      if user.room
         console.log "#{to} <#{from}> #{message}"
       else
-        user.room = null
         console.log "msg <#{from}> #{message}"
 
       self.receive new Robot.TextMessage(user, message)


    bot.addListener 'join', (channel, who) ->
        console.log('%s has joined %s', who, channel)

    bot.addListener 'part', (channel, who, reason) ->
        console.log('%s has left %s: %s', who, channel, reason)

    @bot.part channel, () ->
      console.log('left %s', channel)

  createUser: (channel, from) ->
      user = @userForName from
      unless user?
        id = (new Date().getTime() / 1000).toString().replace('.','')
        user = @userForId id
        user.name = from

      if channel.match(/^[&#]/)
        user.room = channel
      else
        user.room = null
      user

  run: ->
    self = @

