alaingilbert / Turntable-API

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

Vote Skipping #204

Closed ghost closed 11 years ago

ghost commented 11 years ago

I have done research about the vote skipping feature for the bot in chillybot's code but his way is a bit complex.

I want to know how to configure/code a simple version of Vote Skipping for my bot.

Description of Vote Skipping: Voting system for skipping a song.

technobly commented 11 years ago

Make a global array used to count votes

When someone types /skip add their user id to the array if they are not in it already. Decide on whether or not you want to let people in the crowd vote, or just people on the deck. Check to see what's what before you count their vote.

when the array length >= the number of votes you feel is enough, ask the dj to skip their song, and at the same time start a timer that will automatically remove them anyway.

clear the array on newsong.

clear the timer on newsong if it's set.

crack a cold one.

sit back and enjoy your skipping feature.

ghost commented 11 years ago

can I have a example of what it should look like in code format.

technobly commented 11 years ago

I could just copy paste my code, but I figured this would be more fun.

ghost commented 11 years ago

lol, ok. but your the teacher and I am the student.

technobly commented 11 years ago

Step one... make a global array. Show me.

ghost commented 11 years ago

global.voteCount=[];

technobly commented 11 years ago

ok good now add a command for "/skip" that adds userid's to the array, if they are not in the array already. Start off easy and just let anyone vote.

ghost commented 11 years ago

global.voteCount=[]; if(data.text.match(/skip/i))

I got stuck on trying to code the bit for the /skip command to add the userids to the array.

technobly commented 11 years ago

first, put your test in the correct message handler...

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

then escape your '/' and make sure it starts at the beginning of the line in any case like this

if(data.text.match(/^\/skip/i)) {

}

then google on how to add data to arrays. Here's your search terms "javascript arrays"

also at the same place that's teaching you about arrays, figure out how to tell if a value is in an array.

modify your code to test if the userid is already in the array, if not, add it.

alaingilbert commented 11 years ago

I would add «Each line you write, make sure there is no syntax error, and the program behave like you want.»

ghost commented 11 years ago

bot.on('speak', function(data) { } ); global.voteCount=[]; if(data.text.match(/^\/skip/i)) { global.voteCount=voteCount.length global.voteCount=voteCount.indexOf(" ") }

alaingilbert commented 11 years ago

I'll tell you what I see of your program right now:

It make no sense to me. Did you skip my advice ? or it meant something for your computer when you ran it ?

technobly commented 11 years ago

You don't really code at all do you?

I will help a bit here:

global.voteCount = [];

bot.on('speak', function(data) { 
  var text = data.text.trim();
  // .trim() removes any whitespace around your data.text

  if(text.match(/^\/skip/i)) {
    // ^ means regex must match start of string, not anywhere in the string
    // \/ is the backslash escaped
    // skip is your command
    // i at the end makes it case insensitive
    if(voteCount.indexOf(something) < 0) {
      // if something is not in your array, it will return -1, thus the test for less than 0
      // you need to figure out what "something" should be

      // and here you need to add your user's ID that just typed the command to the array

      if(voteCount.length >= 3) {
        // wreck shop
      }
    } 
  }

});

Try using github flavored markdown for javascript in your following posts for code.  Use proper indention! (lesson learned long ago)
ghost commented 11 years ago

I am trying to learn how to code by using Codecademy, http://www.codecademy.com/,

technobly commented 11 years ago

Good! Keep learning and before you know it you will be coding all these up on your own.

I've used these sites heavily when first learning javascript: http://www.w3schools.com/jsref/jsref_obj_array.asp http://www.learnjavaonline.org/ http://stackoverflow.com/questions/tagged/javascript

ghost commented 11 years ago

ok, thanks for the help so far.

technobly commented 11 years ago

I just finished the first 35 lessons on Codecademy.com "Introduction to JavaScript"

I would say that that site is perfect for you, to get you thinking about code in the right way. Experiment a lot! Sprinkle lots of console.log("DEBUG 1"); console.log("DEBUG 2: "+variable); around your code to see what's going on. It will either start to make sense and make you want to do more and more, or just make your brain hurt continuously.

ghost commented 11 years ago

ok