samuri51 / chillybot

a turntable bot created by a moderator of straight_chillin11
12 stars 12 forks source link

autoQ #57

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hi dude,

I've added an auto-re-Q with toggleable on/off and it works a treat for any playlimit that's not 1. For a playlimit of 1 it fires the autoQ code even if you /dive or click the 'Quit Djing' button. Any other value it behaves as expected if you dive etc. Wondered if you can see what I'm missing 'cos I'm going bald from head-scratching!

Any pointers appreciated. I'm making this up as I go...

Code:

    //iterates through the dj list incrementing dj song counts and
    //removing them if they are over the limit.
    var djId = data.room.metadata.current_dj;

    if (typeof (djs20[djId]) !== 'undefined' && typeof djId != 'undefined')
    {
        if (++djs20[djId].nbSong >= playLimit)
        {
            if (PLAYLIMIT === true) //is playlimit on?
            {
                if (djId == currentDjs[0] && playLimit === 1) //if person is in the far left seat and limit is set to one
                {
                    var checklist33 = theUsersList.indexOf(djId) + 1;

                    if (checklist33 !== -1)
                    {
                        bot.speak('@' + theUsersList[checklist33] + ' you are over the playlimit of ' + playLimit + ' song');
                    }
                    bot.remDj(djId);

                    var checkDj = currentDjs.indexOf(djId);
                        if (checkDj != -1) {
                        var name1 = theUsersList.indexOf(djId) + 1; 
                        var list3 = queueList.indexOf(theUsersList[name1]);
                        var checkStageList = stageList.indexOf(djId);
                        var checkManualStageList = bannedFromStage.indexOf(djId);
                        bot.pm('Limit=1', djId)
                        if (list3 == -1 && checkStageList == -1 && checkManualStageList == -1 && djId !== AUTH && autoQ == true)
                            {
                                queueList.push(theUsersList[name1], djId);
                                queueName.push(theUsersList[name1]);
                        bot.pm('autoQ enabled, q- to leave the ride', djId);                        
                    }       
                        }
                }
                else if (djId != USERID && playLimit !== 1) //if limit is more than one
                {
                    var checklist33 = theUsersList.indexOf(djId) + 1;

                    if (checklist33 !== -1)
                    {
                        bot.speak('@' + theUsersList[checklist33] + ' you are over the playlimit of ' + playLimit + ' songs');
                    }
                    bot.remDj(djId);

                    var checkDj = currentDjs.indexOf(djId);
                        if (checkDj != -1) {
                            var name1 = theUsersList.indexOf(djId) + 1; 
                            var list3 = queueList.indexOf(theUsersList[name1]);
                            var checkStageList = stageList.indexOf(djId);
                            var checkManualStageList = bannedFromStage.indexOf(djId);
                        bot.pm('Limit=>1', autoQid)
                        if (list3 == -1 && checkStageList == -1 && checkManualStageList == -1 && djId !== AUTH && autoQ == true)
                            {
                                queueList.push(theUsersList[name1], djId);
                                queueName.push(theUsersList[name1]);
                        bot.pm('autoQ enabled, q- to leave the ride', djId);                        
                            }   
                    }           
            }
        }
    }
}
samuri51 commented 3 years ago

glad u are having fun with the code :-).

both of these code blocks are identical. i suspect you see yourself always getting readded because on 1 this code will fire at the end of a song. and endsong events are triggered when you hop off the stage.

what this means is that its likely not readding you on greater than 1 because when you get off the stage you havent hit your play limit yet.

whereas on 1 you have

samuri51 commented 3 years ago

to clarify... endsong gets triggered when you hop off or leave the room while your song is playing. because your song ended.

on endsong +1 gets added to your playcount

samuri51 commented 3 years ago

another possible cause... i believe rem_dj will fire before end_song because it is declared first in the file.

so another possibility is that that erases your playcount then endsong adds one to it.

causing it to be 1 when ur song is done. so greater than 1 is unreachable while 1 is reachable if u were also in the left dj seat when u dropped.

needs testing

samuri51 commented 3 years ago

actually scratch that last bit. if that was the case the code should not work at all

ghost commented 3 years ago

another possible cause... i believe rem_dj will fire before end_song because it is declared first in the file.

so another possibility is that that erases your playcount then endsong adds one to it.

causing it to be 1 when ur song is done. so greater than 1 is unreachable while 1 is reachable if u were also in the left dj seat when u dropped.

needs testing

I had tell-tales in the two sections showing when it fired for playlimit = 1 and playlimit > 1 and they fire when expected. I suspected it was because on a playlimit of one the hop off event will log a play, so was trying to figure out how to reference 'if (playcount = 1 && /dive or 'quit djing' is true) then skip the requeue bit of code in the playlimit =1 section. I just don't know how to code.

Thanks for confirming that's possibly the issue - still stumped I reckon :) Any pointer as to what I can reference re:above would be gr8, otherwise I'll just keep guessing at it 'til I either find a way to do it or run out of patience ;) I'm enjoying the brain exercise ;) cheer man

ghost commented 3 years ago

You are, of course, exactly right does do same for values over one if you hit the playlimit inc. endsong +1 ;) I needs different logic that does the equivalent of "if playcount >= playlimit && /dive || Quit Djing, Return" or a different place/way to call the reQ - this is fun. tnx again.