alaingilbert / Turntable-API

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

How to handle a bot in an infrequently used room. #147

Closed MikeWills closed 11 years ago

MikeWills commented 11 years ago

I have a bot that sits in a room that isn't used much. I finally figured out that the bot is being booted for inactivity. How do you recommend handling that? Should I post something to chat every hour? Or less?

p0sixninja commented 11 years ago

Possibly by creating a loop such as

setInterval(function() { bot.speak('Your Message Here'); }, 20_60_1000); // Every 20 minutes

Im not completely sure that you could actually stop the AFK police from coming to get you by saying something :/

But maybe you could call a bot.addDj(); Command in the setInterval Function above... Then later at some point bot.remDj();

Let me know if this doesnt work, ill see what i can do to help you.

p0sixninja commented 11 years ago

Im not completely sure as to if deploying a speak command will stop the AFK police from coming and getting you...

setInterval(function() { bot.speak('Your message here'); }, 20_60_1000); // Every 20 minutes

But you could always add your bot as a DJ ( assuming theres a spot open ),

setInterval(function() { bot.addDj(); }, 10_60_1000); // Every 10 minutes

Then later having your bot step down,

setInterval(function() { bot.remDj();

}, 5_60_1000); // Every 5 minutes

Let me know if this doesnt work, ill see what else i can pull out of my hat :)

p0sixninja commented 11 years ago

Im not completely sure as to if deploying a speak command will stop the AFK police from coming and getting you...

setInterval(function() { bot.speak('Your message here'); }, 20_60_1000); // Every 20 minutes

But you could always add your bot as a DJ ( assuming theres a spot open ),

setInterval(function() { bot.addDj(); }, 10_60_1000); // Every 10 minutes

Then later having your bot step down,

setInterval(function() { bot.remDj();

}, 5_60_1000); // Every 5 minutes

Let me know if this doesnt work, ill see what else i can pull out of my hat :)

P0SIXNINJA

MikeWills commented 11 years ago

I'll try the chat. If that doesn't work. I'll just start expirementing.

alaingilbert commented 11 years ago

I don't know ! But if you find something, let me know !

MikeWills commented 11 years ago

I was actually hoping @izzmo would respond. Since his bots sit there for hours on end.

Izzmo commented 11 years ago

As far as I knew, this was only a browser thing since they just check to see the idle time in browser and do things accordingly, which has nothing to do with the server. I was testing a while back and found out you don't need to send the heartbeat either and it will still stay in the room. The heartbeat is for your buddylist and checking in.

Now, I do have checks in place to see if a bot has become "idle" in some way checking to see when the last response was received from the server, and this happens sometimes where a bot needs to be restarted.

The web socket connection with the turntable.fm servers is kind of weird, so it is hard to tell what happens when a socket is suddenly closed.

But, as far as being sent back to the room lobby, metaphorically speaking of course, this doesn't happen with my bots.

A couple weeks ago I was checking uptimes on the bot in dubstep room and it was in there for 9 days straight without a web socket reconnect.

MikeWills commented 11 years ago

Maybe I'll turn on full logging and see what is happening. I was making some assumptions based on what I was seeing in my limited logs. I'll get more details and post my findings.

Izzmo commented 11 years ago

What host are you using?

MikeWills commented 11 years ago

A computer sitting under my desk hosting my website under Ubuntu 12.04 (IIRC)

Izzmo commented 11 years ago

Oh okay, I was going to say try and check to make sure your host supports websockets. It is amazing how many do not. Long polling on turntable.fm is somewhat flakey and could cause this to happen.

MikeWills commented 11 years ago

Here is from my log. I can't tell if it's mySQL or something else.

DrunkenRegular >>> 2013-01-23T19:02:33.123Z | Uptime Check DrunkenRegular >>> 2013-01-23T19:02:33.485Z | Turntable.FM is up. DrunkenRegular >>> 2013-01-23T19:02:33.663Z | TT Up and Bot in room

events.js:48 throw arguments[1]; // Unhandled 'error' event ^ Error: Connection lost: The server closed the connection. at Protocol.end (/home/mikewills/node_modules/mysql/lib/protocol/Protocol.js:68:13) at Socket.onend (stream.js:80:10) at Socket.emit (events.js:88:20) at TCP.onread (net.js:368:51) Forever detected script exited with code: 1 Forever restarting script for 39 time

My code at that point shouldn't be executing anymore. Any thoughts on what I can add for more debugging to pinpoint the issue?

MikeWills commented 11 years ago

Ah... found some more log details:

node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: connect ECONNREFUSED at errnoException (net.js:646:11) at Object.afterConnect as oncomplete

at Handshake.Sequence (/home/mikewills/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:21)
at new Handshake (/home/mikewills/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
at Protocol.handshake (/home/mikewills/node_modules/mysql/lib/protocol/Protocol.js:37:50)
at Connection.connect (/home/mikewills/node_modules/mysql/lib/Connection.js:37:18)
at Connection._implyConnect (/home/mikewills/node_modules/mysql/lib/Connection.js:153:10)
at Connection.query (/home/mikewills/node_modules/mysql/lib/Connection.js:62:8)
at /home/mikewills/ttbots/Uglee/database.js:93:9
at Object.<anonymous> (/home/mikewills/ttbots/Uglee/main.js:33:2)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)

events.js:48 throw arguments[1]; // Unhandled 'error' event ^ Error: Connection lost: The server closed the connection. at Protocol.end (/home/mikewills/node_modules/mysql/lib/protocol/Protocol.js:68:13) at Socket.onend (stream.js:80:10) at Socket.emit (events.js:88:20) at TCP.onread (net.js:368:51)

events.js:48 throw arguments[1]; // Unhandled 'error' event ^ Error: Connection lost: The server closed the connection. at Protocol.end (/home/mikewills/node_modules/mysql/lib/protocol/Protocol.js:68:13) at Socket.onend (stream.js:80:10) at Socket.emit (events.js:88:20) at TCP.onread (net.js:368:51)

Izzmo commented 11 years ago

Looks to me it has to do with your connection to the server your MySQL DB lives. From the stack trace, you can see it is throwing an error out in the MySQL files, which therefor I would assume it is conflicting in there.

MikeWills commented 11 years ago

That is what I was beginning to think after seeing those errors. Since I posted that, the bot has been up just fine. :-/ Crazy.