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

How Do I Use List Rooms? #206

Closed mnafricano closed 11 years ago

mnafricano commented 11 years ago

If I was to make a bot that goes to a room and leaves if there aren't enough listeners, what would I do to have the bot be able to see the rooms, go to one, then leave if it doesn't have enough listeners. Here is the code I have so far:

var Bot = require('ttapi');
var AUTH = "xxxxxxxxxxxxxxxxxxxxxxxx";
var USERID = "518dd6d1aaa5cd34f8e337d1";
var ROOMID = "517e6f80eb35c118d013447c";
var bot = new Bot(AUTH, USERID, ROOMID);

bot.on('ready', function (data) {
    bot.listRooms();
    // Enter a room on the list of data returned.
    if (data.room.listeners <= 5) {
        bot.roomDeregister();
    }
    // Repeat the Process
}

Thanks you for your time and your help, it's very appreciated.

alaingilbert commented 11 years ago
var bot = new Bot(AUTH, USERID);

bot.on('ready', function () {
  bot.listRooms(0, function (data) {
    for (var i=0; i<data.rooms.length; i++) {
      var room = data.rooms[i];
      var listeners = room.metadata.listeners;
      if (listeners > 5) {
        bot.roomRegister(room.roomid);
      }
    }
  });
});
alaingilbert commented 11 years ago

By the way, I think that listRooms return the most popular rooms first. So your bot will always register in the first room.

var bot = new Bot(AUTH, USERID);

bot.on('ready', function () {
  bot.listRooms(0, function (data) {
    bot.roomRegister(data.rooms[0].roomid);
  });
});
mnafricano commented 11 years ago

Awesome, great help! Thanks a ton, I really appreciate it.