 RocketBot.alias = 'bot'
 RocketBot.adapter = new RocketChatAdapter RocketBot
 HubotScripts(RocketBot)
+RocketBot.run()
 
 RocketBot.hear /test/i, (res) ->
 	res.send "Test? TESTING? WE DON'T NEED NO TEST, EVERYTHING WORKS!"

	#
	# Returns nothing.
	send: (envelope, strings...) ->
		console.log envelope, strings
		sendHelper @robot, envelope, strings, (string) =>
			console.log "send #{envelope.room}: #{string} (#{envelope.user.id})" if DEBUG
			RocketChat.sendMessage RocketBot.user, { msg: string }, { _id: envelope.room }

	#
	# Returns nothing
	play: (envelope, strings...) ->
		console.log 'ROCKETCHATADAPTER -> play'.blue

	# Public: Raw method for invoking the bot to run. Extend this.
	#
	# Returns nothing.
	run: ->
		console.log 'ROCKETCHATADAPTER -> run'.blue
		@robot.emit 'connected'
		@robot.brain.mergeData {}
		# @robot.brain.emit 'loaded'

	# Public: Raw method for shutting the bot down. Extend this.
	#
	# Returns nothing.
	close: ->
		console.log 'ROCKETCHATADAPTER -> close'.blue

class RocketBotReceiver
	constructor: (message) ->
		console.log message
		if message.u.username isnt RocketBot.name
			RocketBotUser = new Hubot.User(message.u.username, room: message.rid)
			RocketBotTextMessage = new Hubot.TextMessage(RocketBotUser, message.msg, message._id)
