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

Issues with a snag command #150

Closed soupnrc closed 11 years ago

soupnrc commented 11 years ago

I'm trying to make a snag command and the current code is as follows...

exports.name = 'snag';
exports.hidden = true;
exports.enabled = true;
exports.matchStart = false;
exports.handler = function(data) {
    if(admincheck(data.userid)) {
         bot.playlistAll(function (data) {
                bot.playlistAdd(currentsong.id, data.list.length);
            }); 
        bot.snag();
        output({text: 'Snagging this song, ' + data.name + '!', destination: data.source, userid: data.userid});
    }
}

It gives me the heart fart, but will not add the song to the bot's playlist. I know there are a number of threads on the subject, but any help would be greatly appreciated. Thank you

MikeWills commented 11 years ago

Did you see the warning with the bot.snag() command?

This function will not add the song into the queue, only trigger the heart animation. Use this with a callback to .playlistAdd, or the latter method alone to queue a song;

Use playlistAdd to actually add to the queue.

soupnrc commented 11 years ago

Oh right, I did see that. My question then, is how would that be coded. I'm sure there are a 100 javascript noobs on this site, so I'm sorry if I'm being redundant. I am among the ranks of said javascript babies.

Would it look like this? This is what I have

exports.name = 'snag';
exports.hidden = true;
exports.enabled = true;
exports.matchStart = false;
exports.handler = function(data) {
    if(admincheck(data.userid)) {
         bot.playlistAll(function (data) {
                bot.playlistAdd(currentsong.id, data.list.length, callback);
            }); 
        bot.snag();
        output({text: 'Snagging this song, ' + data.name + '!', destination: data.source, userid: data.userid});
    }
}
technobly commented 11 years ago

Attach this in your /snag command... moderator protected hopefully :)

bot.roomInfo(false, function(data) {
  try {
  var newSong = data.room.metadata.current_song._id;
  var newSongName = data.room.metadata.current_song.metadata.song;
  bot.snag();
  bot.playlistAdd(newSong);
  bot.speak('Added ' + newSongName + ' to the song list.');
  } catch(err) {
      errMsg(err);
  }
});
soupnrc commented 11 years ago

Hey, DubbyTT. I tried the code you gave me to see how it works. There's a syntax error in there somewhere with one of the "}"

However, I was able to get some help from someone in the Indie While You Work room by the name of Mad Johnny. He gave me the following, and it works fine.

exports.name = 'snag';
exports.hidden = true;
exports.enabled = true;
exports.matchStart = true;
exports.handler = function(data) {
    if(admincheck(data.userid)) {
         bot.roomInfo(true, function(data) { var newSong = data.room.metadata.current_song._id; bot.playlistAdd(newSong,10000); bot.snag(); });
        output({text: 'Grabbing this song, ' + data.name + '!', destination: data.source, userid: data.userid});
    }
}

I have the exports.matchstart set to "true" for this one, so be careful if you use this to make sure that your output doesn't start with the word "snag" or your bot will end up in a loop because it will keep thinking someone is asking for it to snag.

technobly commented 11 years ago

Well I'm glad you got it working, but there's no syntax error in my code ;-) I copied it right out of my working bot.

technobly commented 11 years ago

It looks like you may be using sparkle bot there... you probably pasted my code in as is, but you would need to put it in like this....

exports.name = 'snag';
exports.hidden = true;
exports.enabled = true;
exports.matchStart = false;
exports.handler = function(data) {
  if(admincheck(data.userid)) {
    bot.roomInfo(false, function(data) {
      try {
        var newSong = data.room.metadata.current_song._id;
        var newSongName = data.room.metadata.current_song.metadata.song;
        bot.snag();
        bot.playlistAdd(newSong);
        bot.speak('Added ' + newSongName + ' to the song list.');
      } catch(err) {
        errMsg(err);
      }
    });
  }
}

The main difference between this and the code you have working now, is mine adds the song to the top of the queue, while yours adds it to the bottom. I'd almost prefer the bottom... if my bot didn't also use this code for it's DJ CLONE feature ;-)

soupnrc commented 11 years ago

Thank you for the insight. I actually did copy the code in like you have it there, but I think I accidentally removed the bracket right after admincheck, somehow. I was looking to add songs to the end of bot's queue, as well.

Thanks again :)

Izzmo commented 11 years ago

@soupnrc do not forget to close this issue :+1:

soupnrc commented 11 years ago

@izzmo My mistake! Thank you for the help!