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

Cannot call method 'send' #51

Closed mcgrailm closed 12 years ago

mcgrailm commented 12 years ago

downloaded new code for tt fix thats going to happen and when I ran my bot script it faild with this

node.js:134 throw e; // process.nextTick error, or 'error' event on first tick ^ TypeError: Cannot call method 'send' of undefined at [object Object]._send (exmaple.com/uberbot/bot/node_modules/ttapi/bot.js:299:12) at [object Object].bootUser (exmaple.com/uberbot/bot/node_modules/ttapi/bot.js:468:9) at [object Object].startAPI (exmaple.com/uberbot/bot/node_modules/uberbot/uberbot.js:941:14) at Object. (exmaple.com/uberbot/bot/marvin-mixxx.js:220:6) at Module._compile (module.js:407:26) at Object..js (module.js:413:10) at Module.load (module.js:339:31) at Function._load (module.js:298:12) at Array. (module.js:426:10) at EventEmitter._tickCallback (node.js:126:26)

mcgrailm commented 12 years ago

this is where it is breaking for me

Bot.prototype._send = function (rq, callback) { rq.msgid = this._msgId; rq.clientid = this.clientId; rq.userid = rq.userid || this.userId; rq.userauth = this.auth;

var msg = JSON.stringify(rq);

if (this.debug) { if (this.stdout == 'stderr') { console.error('< ' + msg); } else { console.log('< ' + msg); } }

this.ws.send('~m~'+msg.length+'~m~'+msg); this._cmds.push([this._msgId, rq, callback]); this._msgId++; }

in bot.js

alaingilbert commented 12 years ago

May I ask you to show your code ? Or add me on gtalk ! ( alain.gilbert.15 [at] gmail.com )

alaingilbert commented 12 years ago

Apparently an error in the bot code...

mcgrailm commented 12 years ago

thanks for your help

sethgho commented 12 years ago

I'm having this exact error as well. I suspect I might be approaching subclassing the bot incorrectly. Any advice on what I'm doing wrong is welcome!

https://gist.github.com/5556907b3a1e9dc2370f

alaingilbert commented 12 years ago

Hey, You have to wait until the bot is really into the room. In your code, that mean:

myBot.on('roomChanged', function() {
  myBot.greet();
});

NodeJs is asynchrone. The socket wasn't ready.

sethgho commented 12 years ago

shame

I should've looked up from the keyboard and realized this. Too busy second guessing my approach to subclassing.

Thanks for the swift response!