alaingilbert / Turntable-API

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

How Do I Use the Information Returned on Functions Like "directoryGraph" and "stalk?" #205

Closed mnafricano closed 11 years ago

mnafricano commented 11 years ago

I want the bot to speak the information returned for all of the functions possible so that I can see the type of data, but I'm not sure how to get the bot to speak the data returned from a function like that. Thanks!

technobly commented 11 years ago

Your best bet is to use this command and look at the data in the console. It will be easier to see anyway:

console.log(JSON.stringify(data, null, ' '));

where 'data' is whatever your callback variable name is.

technobly commented 11 years ago

to use them, you just access the data like this:

// inside your callback
if(data.success === true) {
  console.log("Welcome to "+data.room.name+"!");
}
mnafricano commented 11 years ago

Wow, that was quick, thank you a lot, I will try that out and tell you my results. @DubbyTT

mnafricano commented 11 years ago

This is my code:

var Bot = require('ttapi');
var AUTH = "xxxxxxxxxxxxxxxxxxxxxxxxx";
var USERID = "51928c88aaa5cd2158211133";
var ROOMID = "517e6f80eb35c118d013447c";
var bot = new Bot(AUTH, USERID, ROOMID);

console.log(JSON.stringify(bot.stalk("51437308aaa5cd0aff8b727d")));

and when I ran it, I got this message:

Bot is not ready. Can't send : 'user.become_fan'
undefined

How do I fix this? @DubbyTT

mnafricano commented 11 years ago

I thought I figured it out but I didn't.

technobly commented 11 years ago

Normally you would wait to start using bot functions until after it has connected. You can use the 'ready' message for this. Or you can use any other event like 'registered' or 'newsong', etc..

var Bot = require('ttapi');
var AUTH = "xxxxxxxxxxxxxxxxxxxxxxxxx";  // I'm assuming you are filling this out on your machine
var USERID = "51928c88aaa5cd2158211133";
var ROOMID = "517e6f80eb35c118d013447c";
var bot = new Bot(AUTH, USERID, ROOMID);

// This will fire after the bot has connected to TT.FM
bot.on('ready', function () {
  bot.stalk("51437308aaa5cd0aff8b727d", function (data) {
    if(data.success) console.log(JSON.stringify(data, null, ' '));
    else console.log("NOPE.avi");
  });
});
technobly commented 11 years ago

updated:

var Bot = require('ttapi');
var AUTH = "xxxxxxxxxxxxxxxxxxxxxxxxx";  // I'm assuming you are filling this out on your machine
var USERID = "51928c88aaa5cd2158211133";
var ROOMID = "517e6f80eb35c118d013447c";
var bot = new Bot(AUTH, USERID, ROOMID);

// This will fire after the bot has connected to TT.FM
bot.on('ready', function () {
  bot.stalk("51437308aaa5cd0aff8b727d", function (data) {
    if(data.success) 
      console.log("Found user in room: " + data.roomId);
    else 
      console.log("User not found, may be offline");
  });
});
technobly commented 11 years ago

Thanks to you @mnafricano, I made a bot that follows me around automatically this afternoon. Now I just need to make it stalk a user of desire and deliver a message, have AI intelligence and return home if it gets bored.

ghost commented 11 years ago

cool, add it to the wiki to share with the rest of us.

alaingilbert commented 11 years ago

@Turntablelover I don't think it is necessary to put every single piece of code imaginable on the wiki. It's simple. Read the documentation. Every events are used the same way. Every actions are used the same way. Then you use your logicto create things.

technobly commented 11 years ago

Per @alaingilbert 's request I will not add it to the wiki :)

BTW I got it working.. delivering messages for online/offline users, following me around... pretty neat.

ghost commented 11 years ago

can you at least show us the code in this post because I would love to add it to my bot.

technobly commented 11 years ago

@Turntablelover are you done coding that voting / skipping feature yet?

ghost commented 11 years ago

no, i forgot about it and went rock mining with my family instead.

technobly commented 11 years ago

@Turntablelover well that sounds like a good use of time. @mnafricano is this issue sufficiently solved?

mnafricano commented 11 years ago

Mhmm, I'm gonna close it right now. Thank you! :smiley:

mnafricano commented 11 years ago

They have trolls on GitHub now? @Turntablelover :stuck_out_tongue:

ghost commented 11 years ago

what?

mnafricano commented 11 years ago

LOL, I'm just kidding! @Turntablelover :laughing:

technobly commented 11 years ago

@mnafricano check your secret gist

mnafricano commented 11 years ago

Thank you so much. By the way, nice comments. What did you use to do those? @DubbyTT