alaingilbert / Turntable-API

Allows you to create bots for turntable.fm
http://alaingilbert.github.com/Turntable-API/
MIT License
318 stars 97 forks source link

dj_bot #263

Open busterbubs opened 10 years ago

busterbubs commented 10 years ago

With the dj_bot, how can I make the bot DJ? I don't see a command in the code that I can type into the chat and make the bot DJ. Same thing in the auto_dj. Please help!

ghost commented 10 years ago

Hi, I am the main coder for the dj_bot and auto_dj files that you have mentioned.

In the code for auto_dj, when you put it into your bot code, your bot automatically djs, when there are a certain number of djs on stage, when you run the code.

In the code for dj_bot, your bot jumps on stage when you do the /go command and he jumps off stage when you do the /stop command.

The bot will skip his song when you do the /skip command when he has the dj_bot code, and the /addsong command adds songs to the bot's playlist.

busterbubs commented 10 years ago

Hello. My bot doesn't hop on stage when i typed /go , and It has some songs in its playlist. Please help.

Thanks, Nick

ghost commented 10 years ago

that's odd, please post your code.

busterbubs commented 10 years ago
var Bot = require('ttapi');
var AUTH = '...';
var USERID = '...';
var ROOMID = '...';

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

bot.on('speak', function (data) {
  var text = data.text;
  if (text == '/go') {
    // Bot gets on the DJ table (if there's a spot open) on /go command
    bot.addDj();
  } else if (text == '/silly stop') {
    // Bot jumps off the table on /silly floor command
    bot.remDj();
  } else if (text == '/silly skip') {
    // Bot skips it's own song (if bot is the current DJ) on /silly skip command
    bot.skip();
  } else if (text == 'silly snag') {
    // Bot adds song to the bottom of it's DJ queue on /silly snag command
    bot.playlistAll(function (data) {
      bot.playlistAdd(songId, data.list.length);
    });
    bot.snag();
  }
});

bot.on('speak', function (data) {
  var text = data.text;

  // Any command with "bop" in it will work (ex: "bop","bop i beg you!!!","lolbopbaby", etc.)
  if (text.match(/bop/)) {
    bot.vote('up');
  }
});

bot.on('roomChanged', 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;
 {
    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 = true;
  }

  // If triggered to get down during Bot's song, step down now
  if (getDownAfterSong) {
    bot.remDj();
    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();
      }
    }
  });
});

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();
    }
  });
});

var modList = ['xxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxx'];

// When someone is a moderator in the array AND types in "/mod", the bot displays a message.
bot.on('speak', function (data) {
  var name = data.name;
  var text = data.text;
  var userid = data.userid;

  for (var i=0; i<modList.length; i++) {
    if (userid == modList[i]) {
      // Respond to "/mod" command
      if (data.text.match(/^\/mod$/)) {
        bot.speak('Yo @'+data.name+', it looks like you are a bot moderator!');
      }
      // ADD other moderator commands here!
      break;
    }
  }
});
busterbubs commented 10 years ago

Do you see anything I should fix?

ghost commented 10 years ago

Remove this code:

bot.on('speak', function (data) {
var text = data.text;
if (text == '/go') {
// Bot gets on the DJ table (if there's a spot open) on /go command
bot.addDj();
} else if (text == '/silly stop') {
// Bot jumps off the table on /silly floor command
bot.remDj();
} else if (text == '/silly skip') {
// Bot skips it's own song (if bot is the current DJ) on /silly skip command
bot.skip();
} else if (text == 'silly snag') {
// Bot adds song to the bottom of it's DJ queue on /silly snag command
bot.playlistAll(function (data) {
bot.playlistAdd(songId, data.list.length);
});
bot.snag();
}
});

It is interfering with your auto-dj code:

 bot.on('roomChanged', 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;
{
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 = true;
}

// If triggered to get down during Bot's song, step down now
if (getDownAfterSong) {
bot.remDj();
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();
}
}
});
});

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();
}
});
});
busterbubs commented 10 years ago

ok, did that. what is the command to make it hop on stage? i typed /go , nothing happened.

Thanks, Nick

Izzmo commented 10 years ago

@busterbubs try checking out the wiki page on github, it will have the answer you seek!

busterbubs commented 10 years ago

is it *youcandj ? didnt work @Izzmo

busterbubs commented 10 years ago

all i want is for the bot to DJ. please help :(

Thanks, Nick

alaingilbert commented 10 years ago
var Bot = require('ttapi');
var bot = new Bot(AUTH, USERID, ROOMID);
bot.on('roomChanged', function() {
  bot.addDj();
});

If you only want him to go on stage, this is the code you need. Your bot will step on the stage as soon as he enter the room. (if there is an open spot)