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

New Examples(Fixed Version 3.0) #179

Closed ghost closed 11 years ago

ghost commented 11 years ago

Added Auto DJ Bot, Autosnag, and Manual DJ Bot. Fixed coding to 2 spaces indented with the Tab button.

I used the link you gave me and it said to use the tab button. I hope this is correct.

:)

alaingilbert commented 11 years ago

I don't think you understand the concept of "indentation". By the way, don't close this pull request, instead, modify it. So we'll be able to keep the discussion.

Check this out, for a good pull request workflow: https://www.openshift.com/wiki/github-workflow-for-submitting-pull-requests

Check this out for a good "squash" example: «What this does is take smaller commits and combine them into larger ones» http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html http://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits

ghost commented 11 years ago

ok, how can I indent it properly.

alaingilbert commented 11 years ago

Also, the link I sent explain how and where you should put spaces in front of your lines of code. http://site.chronic667.com/gm/tutorials/Tutorial%20-%20Indenting%20your%20code.html

So, basically, every lines inside a "block" should be indented (mean: you add 2 spaces in front of them). example:

instead of

if () {
CODE;
CODE;
}

you will have

if () {
..CODE;
..CODE;
}

(where the dots are in fact "spaces")

ghost commented 11 years ago

so, should I use the Tab button or the Space Bar

alaingilbert commented 11 years ago

In my text editor, the tab button is adding two space.

ghost commented 11 years ago

ok, I use Notepad++

alaingilbert commented 11 years ago

you can (should) change the setting. So the tab button will add spaces instead. http://stackoverflow.com/questions/455037/notepad-tabs-to-spaces

ghost commented 11 years ago

ok, I checked the settings and there was no option to make the tab button add spaces instead.

alaingilbert commented 11 years ago

...

ghost commented 11 years ago

ok, thanks

ghost commented 11 years ago

Does it look good enough to merge.

alaingilbert commented 11 years ago

Not at all. Indent your code.

ghost commented 11 years ago

ok, thanks for the quick response.

technobly commented 11 years ago

Get Sublime Text 2 http://www.sublimetext.com and add Package Control and the JsFormat package. Create a new file, paste your code in, change syntax to Javascript, select all (CTRL+A) and press CTRL+ALT+F to Beautify your code automatically! Default is two spaces for TAB, and looks good. Hopefully 4 spaces is not necessary because once you start nesting a bunch of code it's going to get out of control! Here's what it looks like with 2 spaces. http://i.imgur.com/DoOpgVQ.png

technobly commented 11 years ago

Also something that sticks out to me is your javascript bot.roomInfo(true, function(data) { should be javascript bot.roomInfo(false, function(data) { to save time on the call and amount of data returned. "false" doesn't include all of the song log info. So if you don't need that, it's a good idea not to ask for it.

ghost commented 11 years ago

ok

technobly commented 11 years ago

@Turntablelover, your indenting is still off. http://i.imgur.com/Ma8T6en.png

https://github.com/Turntablelover/Turntable-API/blob/08b62f876a3826363a1048665a0bc0328395a198/examples/autodj.js

ghost commented 11 years ago

Does the coding look right with the correct indentions

alaingilbert commented 11 years ago

lot better, but still wrong !

you shouldn't have these

});
});

on the same line... if it was good.

ghost commented 11 years ago

Pushing out a commit right now, that will fix it. It should appear in here in a bit for you to look at.

alaingilbert commented 11 years ago

I said "fix the indentation", not "break your code" Now, if you try to run your code, you'll end up with a lot of errors saying that you are missing some }.

alaingilbert commented 11 years ago

I don't know, maybe you should test the code you are committing (?) And learn how to properly indent your code. (http://www.cs.arizona.edu/~mccann/indent_c.html) (following the style of the project)

samuri51 commented 11 years ago

@Turntablelover this is what ur code should look like... although i won't test it for u :p

var Bot = require('ttapi');
var AUTH = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var USERID = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var ROOMID = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var imDjing = false;
var getDownAfterSong = false;

var bot = new Bot(AUTH, USERID, ROOMID);

bot.on('roomChanged', function (data) {
    bot.roomInfo(false, function (data) {
        // Get the DJ count upon entering the room
        var djcount = data.room.metadata.djcount;
        // If DJ count less than or equal to 1, get on decks    
        if (djcount <= 1) {
            bot.addDj();
        }
    });
});

bot.on('newsong', function (data) {
    // Check if bot is the new DJ when new song begins
    var djid = data.room.metadata.current_song.djid;
    if (djid == USERID) {
        imDjing = true;
    }
});

bot.on('endsong', function (data) {
    // Update 'imDjing' when Bot's song ends
    var djid = data.room.metadata.current_song.djid;
    if (djid == USERID) {
        imDjing = false;
    }

    // If triggered to get down during Bot's song, step down now
    if (getDownAfterSong == true) {
        bot.remDj(USERID);
        getDownAfterSong = false;
    }
});

bot.on('add_dj', function (data) {
    // Check the DJ count when a new DJ steps up
    bot.roomInfo(false, function (data) {
        var djcount = data.room.metadata.djcount;
        // If there's enough DJ's now, bot steps down.  
        if (djcount >= 3) {
            // If bot's song is currently playing, let's have the bot step down when it ends
            if (imDjing) {
                getDownAfterSong = true;
            } else {
                bot.remDj(USERID);
            }
        }
    });
});

bot.on('rem_dj', function (data) {
    // Checks DJ count when a DJ steps down
    bot.roomInfo(false, function (data) {
        var djcount = data.room.metadata.djcount;
        // If there aren't enough DJ's, bot steps up
        if (djcount <= 1) {
            bot.addDj();
        }
    });
});
ghost commented 11 years ago

this is very stressful, but is the code for all 3 examples wrong or not.

samuri51 commented 11 years ago

just do it the lazy way... copy paste ur code into here and specify parameters :p

http://jsbeautifier.org/

samuri51 commented 11 years ago

but yeah as far as indentations go, one thing to note is to never use tabs since they show up differently in every editor. and if you are going to use tabs find the area in the editor and set it to represent tabs as spaces... the standard is 2 - 4. i personally prefer braces on their own line but i know most ppl dont. but theres more than one way to legitimately indent your code.

samuri51 commented 11 years ago

this is braces on own line... u can do it this way too


bot.on('rem_dj', function (data)
{
    // Checks DJ count when a DJ steps down
    bot.roomInfo(false, function (data)
    {
        var djcount = data.room.metadata.djcount;
        // If there aren't enough DJ's, bot steps up
        if (djcount <= 1)
        {
            bot.addDj();
        }
    });
});
alaingilbert commented 11 years ago

That looks great ! You only forgot what I said before, that you should use ("2" / "two" / "deux") spaces. Actually you use 4 spaces.

Fix that, squash your 14 commits into one with git rebase -i master (http://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) And I'll merge it right away !

ghost commented 11 years ago

squashing the 14 commits into one is pretty confusing.

alaingilbert commented 11 years ago

http://youtu.be/msuJGG2iWjs

ghost commented 11 years ago

I used git rebase -i master and it said it's not a git repository

technobly commented 11 years ago

I really admire the determination of this thread... it's like an everlasting gobstopper. Not even Willy Wonka himself is going to tell you what to do with it, you just have to figure it out for yourself.

kernelsmith commented 11 years ago

I have to agree w/@DubbyTT. Some flavors are good and some are hilariously awful.

ghost commented 11 years ago

I am doing this the simplest way possible, so I went ahead and made a new pull request for the final code.