alaingilbert / Turntable-API

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

Random Phrase #188

Closed ghost closed 11 years ago

ghost commented 11 years ago

I got the bot to talk when I mention his name but he says all of the phrases at the same time. So I want to know, how to make him say the phrases randomly whenever I mention his name.

ghost commented 11 years ago

Here is the code I have for the feature:

bot.on('speak', function(data) { if(data.text.match(/VeggieBot/i)) { bot.speak('Exterminate, Exterminate'); }

if(data.text.match(/VeggieBot/i)) { bot.speak('This room is so cold'); }

if(data.text.match(/VeggieBot/i)) { bot.speak('Always eat your vegetables'); } });

samuri51 commented 11 years ago

like this?

bot.on('speak', function (data)
{
    if (data.text.match(/VeggieBot/i))
    {
        switch (Math.round(Math.random() * 2))
        {
        case 0:
            bot.speak('Exterminate, Exterminate');
            break;
        case 1:
            bot.speak('This room is so cold');
            break;
        case 2:
            bot.speak('Always eat your vegetables');
            break;
        }
    }
});
ghost commented 11 years ago

ok, thank you. tested out the code and it worked great.

MikeWills commented 11 years ago

@Turntablelover don't get me wrong. We all love to help a new person out. But personally, I would like to see the person put some effort into either trying themselves, or doing some research. Then when you ask the question, show us what you have tried or where you are confused.