samuri51 / chillybot

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

Discovered a Bug #45

Closed ghost closed 10 years ago

ghost commented 10 years ago

When I was testing out a new feature on Chillster, this morning, the /stable command made him say multiple lines from the database instead of 1.

Code:

//Stable Database
bot.on('speak', function (data)
{
    if (data.text.match(/stable/i))
    {
        switch (Math.round(Math.random() * 20 ))
        {
        case 0:
            bot.speak('I am super stable. I can run for hours.');
            break;
        case 1:
            bot.speak('I am pretty stable. I can run for a couple of hours with no crashs.');
            break;
        case 2:
            bot.speak('I am stable, but my feet are shaking a bit.');
            break;
        case 3:
            bot.speak('I am pretty unstable. My code is filled with bugs or unrecognized code. I will crash like crazy.');
            break;
        case 4:
            bot.speak('I am unstable. My code is buggish.');
            break;
        case 5:
            bot.speak('I am stable. My code has recognized code.');
            break;
        case 6:
            bot.speak('I am super stable. I drank my daily can of soda.');
            break;
        case 7:
            bot.speak('I am unstable. I am half-asleep.');
            break;
        case 8:
            bot.speak('I am unstable. My legs are asleep.');
            break;
        case 9:
            bot.speak('I am stable. I am wide awake and ready for action.');
            break;
        case 10:
            bot.speak('I am unstable. My battery power is low');
            break;
        case 11:
            bot.speak('I am about to crash. AHHHHHHHHHHH!!!!!');
            break;
        case 12:
            bot.speak('My battery power is in the super low danger zone.');
            break;
        case 13:
            bot.speak('I am unstable. My battery is in the red zone.');
            break;
        case 14:
            bot.speak('I am stable. I am running at a super huge rate.');
            break;
        case 15:
            bot.speak('My battery is about to die.');
            break;
        case 16:
            bot.speak('I am half-asleep.');
            break;
        case 17:
            bot.speak('About to fall asleep and crash. Need more soda.');
            break;
        case 18:
            bot.speak('I am super hyper. I drank a lot of soda to stay awake.');
            break;
        case 19:
            bot.speak('I am about to crash. *yawns*');
            break;
        case 20:
            bot.speak('So sleepy. *puts his head down on the pillow');
            break;
        }
    }
});
samuri51 commented 10 years ago

its because you have the word stable inside of your phrases, and its matching that, and as a result saying something else. since the bot is just an account with a script attached to it, when it says something the speak event is triggered like if anyone else was to say something. it then attempts to match words in its own phrase, you either have to change the regex or add extra conditions which i have done below.

try changing

if (data.text.match(/stable/i))

to

if (data.text.match(/stable/i) && data.userid != USERID)

assuming the AUTH, USERID, ROOMID, variables in your script haven't been changed to mean something different, this should tell the bot not to attempt a match when its the one saying one of these phrases

ghost commented 10 years ago

Thanks for the help. :)