Closed mnafricano closed 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.
to use them, you just access the data like this:
// inside your callback
if(data.success === true) {
console.log("Welcome to "+data.room.name+"!");
}
Wow, that was quick, thank you a lot, I will try that out and tell you my results. @DubbyTT
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
I thought I figured it out but I didn't.
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");
});
});
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");
});
});
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.
cool, add it to the wiki to share with the rest of us.
@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 logic
to create things.
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.
can you at least show us the code in this post because I would love to add it to my bot.
@Turntablelover are you done coding that voting / skipping feature yet?
no, i forgot about it and went rock mining with my family instead.
@Turntablelover well that sounds like a good use of time. @mnafricano is this issue sufficiently solved?
Mhmm, I'm gonna close it right now. Thank you! :smiley:
They have trolls on GitHub now? @Turntablelover :stuck_out_tongue:
what?
LOL, I'm just kidding! @Turntablelover :laughing:
@mnafricano check your secret gist
Thank you so much. By the way, nice comments. What did you use to do those? @DubbyTT
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!