var _ = require('lodash');
var Moment = require('moment');
var Ranger = require('ranger');

var config = require('../core/util').getConfig().campfire;

var Actor = function() {
  _.bindAll(this);

  this.commands = [{
    'handler': 'advice',
    'callback': this.sayAdvice,
    'description': "Advice on what position to take, depending on the current trend"
  }, {
    'handler': 'price',
    'callback': this.sayPrice,
    'description': "The current price of the asset in the configured currency"
  }, {
    'handler': 'donate',
    'callback': this.sayDonate,
    'description': "Where to send all of that extra coin that's weighing you down"
  }, {
    'handler': 'help',
    'callback': this.sayHelp,
    'description': "You are here"
  }];

  this.advice = null;
  this.adviceTime = Moment.utc();
  this.price = null;
  this.priceTime = Moment.utc();

  this.client = Ranger.createClient(config.account, config.apiKey);
  this.client.room(config.roomId, this.joinRoom);
};

Actor.prototype = {
  processTrade: function(trade) {
    this.price = trade.price;
    this.priceTime = Moment.unix(trade.date);
  },

  processAdvice: function(advice) {
    this.advice = advice.recommandation;
    this.adviceTime = Moment.utc();

    if (config.emitUpdates) {
      this.sayAdvice();
    }
  },

  sayAdvice: function() {
    var message;

    if (this.advice !== null) {
      message = ["We think you should", this.advice + ".", "(" + this.adviceTime.fromNow() + ")"];
    } else {
      message = ["We don't have any advice for you quite yet."];
    }

    this.room.speak(message.join(' '));
  },

  sayPrice: function() {
    var message;

    if (this.price !== null) {
      message = ["The price at the moment is", this.price + ".", "(" + this.priceTime.fromNow() + ")"];
    } else {
      message = ["We don't know the price right now."];
    }

    this.room.speak(message.join(' '));
  },

  sayDonate: function() {
    this.room.speak("If you'd like to donate a few coins, you can send them here: 13r1jyivitShUiv9FJvjLH7Nh1ZZptumwW");
  },

  sayHelp: function() {
    this.room.speak("I listen for the following inquiries...", this.pasteDescriptions);
  },

  pasteDescriptions: function() {
    var descriptions = _.map(this.commands, function(command) {
      return [command.handler + ':', command.description].join(' ');
    }, this).join('\n');

    this.room.paste(descriptions);
  },

  joinRoom: function(room) {
    this.room = room;
    this.room.join(this.listenForCommands);
  },

  listenForCommands: function() {
    this.room.listen(this.executeCommands);
  },

  executeCommands: function(message) {
    var nickname = new RegExp(config.nickname, 'i'), handler;

    _.each(this.commands, function(command) {
      handler = new RegExp(command.handler, 'i');

      if (message.body.match(nickname) && message.body.match(handler)) {
        command.callback();
      }
    }, this);
  }
};

module.exports = Actor;

@@ -971,16 +971,47 @@
 nRoom);%0A
+  this.client.me(this.whoAmI);%0A
 %7D;%0A%0AActo
@@ -2664,285 +2664,853 @@
     
-var nickname = new RegExp(config.nickname, 'i'), handler;%0A%0A    _.each(this.commands, function(command) %7B%0A      handler = new RegExp(command.handler, 'i'
+if (message.userId === this.user.id) return false; // Make the bot ignore itself%0A    if (message.body === null) return false; // Handle weird cases where body is null sometimes%0A%0A    _.each(this.commands, function(command) %7B%0A      if (this.textHasCommandForBot(message.body, config.nickname, command.handler)) %7B%0A        command.callback(
 );%0A
-%0A
       
-if (message.body.match(nickname) && message.body.match(handler)) %7B%0A        command.callback()
+%7D%0A    %7D, this);%0A  %7D,%0A%0A  textHasCommandForBot: function(text, nickname, handler) %7B%0A    var normalizedText = text.toLowerCase(),%0A        normalizedNickname = nickname.toLowerCase(),%0A        normalizedHandler = handler.toLowerCase();%0A%0A    var nicknameWasMentioned = normalizedText.indexOf(normalizedNickname) %3E= 0,%0A        handlerWasMentioned = normalizedText.indexOf(normalizedHandler) %3E= 0
 ;%0A
+%0A
     
+return nicknameWasMentioned && handlerWasMentioned;%0A
   %7D
+,%0A
 %0A  
-  %7D, this)
+whoAmI: function(user) %7B%0A    this.user = user
 ;%0A  

Use indexOf for command matching, and don't let the bot listen to itself