samuri51 / chillybot

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

vip add/remove #33

Closed samuri51 closed 11 years ago

samuri51 commented 11 years ago
global.tempVip; //command based vip list

bot.on('speak',function(data)
{
    if(data.text.match(/^\/vip/i) && condition === true) //condition true, means is a mod
    {
        var name = data.text.slice(6).trim().toLowerCase(); //works with @name
        var isVip = tempVip.indexOf(name); //check whether or not already vip

        if(isVip === -1) //not in vip list
        {
            bot.getUserId(name, function(data2)
            {
                if(typeof data2.userid !== 'undefined') //if userid exists, then user exists
                {
                    tempVip.push(name); //add them to vip list
                    bot.speak(name + ' has been added to the vip list.');
                }
                else
                {
                    bot.speak('sorry but i couldn\'t find the person you specified');
                }
            });
        }
        else //they are already a vip
        {
            tempVip.splice(isVip, 1);
            bot.speak(name + ' has been removed from the vip list.');        
        }      
    }
    else if(data.text.match(/^\/whosvip/i) && condition === true)
    {
        if(tempVip.length !== 0) //if there are people in the vip list
        {
            var names = '';

            //add names together
            for(var i = 0; i < tempVip.length; i++)
            {
                if(i < tempVip.length - 1) //if not on the last name
                {
                    names += tempVip[i] + ', ';
                }
                else
                {
                    names += tempVip[i];
                }            
            }        

            //speak the names in chat
            bot.speak(names);
        }    
        else
        {
            bot.speak('the vip list is currently empty.');
        }
    }
});
samuri51 commented 11 years ago

change the contents of the vipListCheck function to this.

you can see what i mean on line 507 of the stock chillybot script


//this kicks all users off stage when the vip list is not empty
    if (vipList.length !== 0 && currentDjs.length != vipList.length) //manual added
    {
        for (var p = 0; p < currentDjs.length; p++)
        {
            var checkIfVip = vipList.indexOf(currentDjs[p]);
            if (checkIfVip == -1 && currentDjs[p] != USERID)
            {
                bot.remDj(currentDjs[p]);
            }
        }
    }
    else if(tempVip.length !== 0 && currentDjs.length != tempVip.length) //command added
    {
        for(var i = 0; i < tempVip.length; i++)
        {
            var checkTempVip = tempVip.indexOf(currentDjs[i]);

            //if currently being looked at dj is not a vip, and 
            //they are not your bot
            if(checkTempVip == -1 && currentDjs[i] != USERID)
            {
                bot.remDj(currentDjs[i]);
            }        
        }    
    }

change the code inside of the 'add_dj' event that corresponds to the following code, to this. starts around line 2617 in the stock chillybot script.

//removes dj when they try to join the stage if the vip list has members in it.
    //does not remove the bot
    var checkVip = vipList.indexOf(data.user[0].userid);
    var checkTempVip = tempVip.indexOf(data.user[0].userid);
    if (vipList.length !== 0 && checkVip == -1 && data.user[0].userid != USERID)
    {
        bot.remDj(data.user[0].userid);
        bot.pm('The vip list is currently active, only the vips may dj at this time', data.user[0].userid);

        if (typeof people[data.user[0].userid] != 'undefined')
        {
            ++people[data.user[0].userid].spamCount;
        }

        if (timer[data.user[0].userid] !== null)
        {
            clearTimeout(timer[data.user[0].userid]);
            timer[data.user[0].userid] = null;
        }

        timer[data.user[0].userid] = setTimeout(function ()
        {
            people[data.user[0].userid] = {
                spamCount: 0
            };
        }, 10 * 1000);
    }
    else if(tempVip.length !== 0 && checkTempVip == -1 && data.user[0].userid != USERID)
    {
        bot.remDj(data.user[0].userid);
        bot.pm('The vip list is currently active, only the vips may dj at this time', data.user[0].userid);

        if (typeof people[data.user[0].userid] != 'undefined')
        {
            ++people[data.user[0].userid].spamCount;
        }

        if (timer[data.user[0].userid] !== null)
        {
            clearTimeout(timer[data.user[0].userid]);
            timer[data.user[0].userid] = null;
        }

        timer[data.user[0].userid] = setTimeout(function ()
        {
            people[data.user[0].userid] = {
                spamCount: 0
            };
        }, 10 * 1000);    
    }