-
Notifications
You must be signed in to change notification settings - Fork 11
basic bot example
samuri51 edited this page Jan 11, 2013
·
1 revision
very basic bot to give you an idea of how to make your own and how to modify commands
var Bot = require('ttapi');
var AUTH = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'; //set the auth of your bot here.
var USERID = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'; //set the userid of your bot here.
var ROOMID = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'; //set the roomid of the room you want the bot to go to here.
var bot = new Bot(AUTH, USERID, ROOMID); //this initiates the bot
bot.listen(8000, '127.0.0.1'); //pings localhost, not needed to run on your computer, but needed to host on a server
bot.on('speak', function (data) //waits till someone says something then executes code inside
{
var name = data.name; //the speakers name
var text = data.text; //the chatbox on turntable
if (text.match(/^\/hello/)) //the strange characters are regular expressions, used to match text
{ //this means it will only match the word at the beggining of the text box
bot.speak('@' + name + ' hello!');
}
else if (text.match(/^\/goodbye/)) //everything after the first statement has to be else if
{ //this means it will search for a match and only the code inside the match
bot.speak('@' + name + ' goodbye!'); //will be executed
}
else if (text.match('/chilly')) //this will match the word anywhere in the text box, not just the beggining
{
bot.speak('@' + name + ' is chilled'); //bot.speak makes the bot speak
}
});