var Bot = require('ttapi');
var AUTH = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var USERID = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var ROOMID = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var imDjing = false;
var getDownAfterSong = false;

var bot = new Bot(AUTH, USERID, ROOMID);

bot.on('roomChanged', function (data) {
  bot.roomInfo(false, function (data) {
    // Get the DJ count upon entering the room
    var djcount = data.room.metadata.djcount;
    // If DJ count less than or equal to 1, get on decks 	
    if (djcount <= 1) {
      bot.addDj();
    }
  });
});

bot.on('newsong', function (data) {
  // Check if bot is the new DJ when new song begins
  var djid = data.room.metadata.current_song.djid;
  if (djid == USERID) {
    imDjing = true;
  }
});

bot.on('endsong', function (data) {
  // Update 'imDjing' when Bot's song ends
  var djid = data.room.metadata.current_song.djid;
  if (djid == USERID) {
    imDjing = false;
  }

  // If triggered to get down during Bot's song, step down now
  if (getDownAfterSong == true) {
    bot.remDj(USERID);
    getDownAfterSong = false;
  }
});

bot.on('add_dj', function (data) {
  // Check the DJ count when a new DJ steps up
  bot.roomInfo(false, function (data) {
    var djcount = data.room.metadata.djcount;
    // If there's enough DJ's now, bot steps down.	
    if (djcount >= 3) {
      // If bot's song is currently playing, let's have the bot step down when it ends
      if (imDjing) {
        getDownAfterSong = true;
      } else {
        bot.remDj(USERID);
      }
    }
  });
});

bot.on('rem_dj', function (data) {
  // Checks DJ count when a DJ steps down
  bot.roomInfo(false, function (data) {
    var djcount = data.room.metadata.djcount;
    // If there aren't enough DJ's, bot steps up
    if (djcount <= 1) {
      bot.addDj();
    }
  });
});
@@ -280,50 +280,8 @@
 ) %7B%0A
-  bot.roomInfo(false, function (data) %7B%0A  
   //
@@ -321,18 +321,16 @@
 he room%0A
-  
   var dj
@@ -363,26 +363,24 @@
 .djcount;%0A  
- 
- 
 // If DJ cou
@@ -423,13 +423,9 @@
 ecks
- %09%0A  
+%0A
   if
@@ -438,34 +438,32 @@
 unt %3C= 1) %7B%0A    
-  
 bot.addDj();%0A   
@@ -461,26 +461,18 @@
 Dj();%0A  
- 
- 
 %7D%0A
-  %7D);%0A
 %7D);%0A%0Abot
@@ -930,16 +930,8 @@
 Song
- == true
 ) %7B%0A
@@ -940,30 +940,24 @@
   bot.remDj(
-USERID
 );%0A    getDo
@@ -1404,22 +1404,16 @@
 t.remDj(
-USERID
 );%0A     
@@ -1687,23 +1687,24 @@
 ddDj();%0A    %7D%0A  %7D);%0A
-
 %7D);
+%0A

remove useless code