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

Endsong command issue. Bot spams :( #142

Closed p0sixninja closed 11 years ago

p0sixninja commented 11 years ago

Hello There!

Im having a issue with this script,

bot.on('endsong', function(data) { ups = data.room.metadata.upvotes; downs = data.room.metadata.downvotes; bot.speak('Up-votes: ' + ups + ', Down-votes: ' + downs); });

It runs just fine, but for some reason it just spams the chatroom with the data received from the function, until it seems the bot is disabled from talking for a short period of time... Is there any way to fix this??

Spam_Chat_Robot


Is there any way i could display the songs name on the console when the song starts playing? I understand the 'newsong' command, but im a little confused on how/what variable it would be to recall the variable set from the newsong command into a console.log(NEWSONGNAMEHERE)


Third And Last Question :P,

Is there any way i can add color to my node.js console? Iv seen sparklebot do it, but im just curious as how i could incorperate it into my console....

THANK YOU SO MUCH ONCE AGAIN! :D

p0sixninja commented 11 years ago

Spam_Chat_Robot2 Well... Now i seem to be having the same exact issue with the bot.say on the interval clock now, so every 10 seconds, my chat is spammed like a million times saying "Welcome, Sorry About the Buggy Bot!, It is under construction", Kinda Explains Itself alot by saying its buggy :P

If you would like to take a look at my code, here it is:

http://pastebin.com/DXPEyjCH

Thanks For Your Help

p0sixninja commented 11 years ago

I Figured Out How To Do Some Colorizing, Theres a excellent JS code called colorize, i forked it :P.... Currently working on setting it up..

Thanks, Now if i could fix the spam issue :D

technobly commented 11 years ago

@p0sixninja, I fixed up your code a bit. You had your endsong and update_votes INSIDE the speak handler, so every time the chat got updated, those functions would get called. I added some nice things in there... study it for a bit and ask me any questions you want about it.

http://pastebin.com/M9Z6QHEd

technobly commented 11 years ago

@p0sixninja, as for newsong data in the console:

bot.on('newsong', function (data) { 

  var currentdj = data.room.metadata.current_dj;
  var song = data.room.metadata.current_song.metadata.song;
  var artist = data.room.metadata.current_song.metadata.artist;
  var album = data.room.metadata.current_song.metadata.album;
  var length = data.room.metadata.current_song.metadata.length;
  var song_id = data.room.metadata.current_song._id;

  //If you are keeping track of the users in your room, you can look up the name
  var username = theUsersList[currentdj].name;

  Log("[ NEW SONG ] : "+username+" started playing: "+song+" by "+artist+" "+length+" "+song_id);

});
technobly commented 11 years ago

@p0sixninja, I just updated the pastebin link with colorize code... http://pastebin.com/M9Z6QHEd I've tested it in my bot and it works! Thanks for this I was wondering how to do this and just never thought to look.

This is essential the part that does the colorizing:

// https://github.com/mattpat/colorize
// Install with "npm install colorize"
// Example:
//  #bold[Welcome to the #green[Green Machine] tool!]
// Currently colorize supports the standard set of 8 ANSI colors 
// (black, red, green, yellow, blue, magenta, cyan, white), 
// along with bold, italic, underline, blink, and a special "reset" keyword.
global.colorize = require('colorize'); //Add color to the console!
global.cconsole = colorize.console;

function Log (msg) {
  cconsole.log(msg);
}

Log('#green[Script Started]');
p0sixninja commented 11 years ago

It still spams the room ;/ as well as the console.... But thanks

technobly commented 11 years ago

@p0sixninja O_O wut... no way man... make sure you are running the right file. I'll actually go test it now myself.

p0sixninja commented 11 years ago

// endsong event function bot.on('endsong', function(data) { ups = data.room.metadata.upvotes; downs = data.room.metadata.downvotes; bot.speak('Up-votes: ' + ups + ', Down-votes: ' + downs); });

This is the one you provided, it still spams the chat box still, im scratching my head at this one... Spam_Chat_Robot3

technobly commented 11 years ago

I'm testing it right now and it's working... there were some other bugs though. Once I know it works completely I'll report back.

p0sixninja commented 11 years ago

THANK YOU!

technobly commented 11 years ago

@p0sixninja ok it's working, please just run the entire file I provide here: http://pastebin.com/M9Z6QHEd

p0sixninja commented 11 years ago

@DubbyTT Thank you for your help, however i would like to figure out why this is doing this, and prevent it from happening in my future scripts, your help is so appreciated..... @alaingilbert do you have any insight as to why this issue is happening, and how i could prevent it?

technobly commented 11 years ago

@p0sixninja I just got done running the file I provided you and it works fine... I'll draw a picture to show you why your code was doing what it was doing.

alaingilbert commented 11 years ago

The spam is happening because you did something like this :

bot.on('speak', function(data) {

bot.on('endsong'...);

});

Basically what is happening is that every time, someone is speaking, you add a new listener for the "endsong" event. So, when the endsong is called, there is like "20" (or more, this number is fictive) callbacks binded to this signal...

p0sixninja commented 11 years ago

@alaingilbert , So to fix this i just need to make sure the endsong is not under a speak function?

Thanks

alaingilbert commented 11 years ago

In your example it should be something like :

bot.on('speak', function(data) {
});

bot.on('endsong'...);

instead

p0sixninja commented 11 years ago

Ohhh! Okay! I see what is going on here!, Thank you @alaingilbert And @DubbyTT !

technobly commented 11 years ago

@p0sixninja I guess it's easier to type that then what I did... here it is anyway :)

http://i.imgur.com/Hbyey.png

p0sixninja commented 11 years ago

THANKS FOR DOING THIS!!! THAT IS A EXCELLENT DRAWING :D