Closed ghost closed 11 years ago
Here's the code for the bot. It has been the same since i upgraded the ttapi module to 2.1.9 a couple of days ago.
var Bot = require('ttapi');
var AUTH = 'xxx';
var USERID = 'xxx';
var ROOMID = '4e386d5814169c294618267b';
var bot = new Bot(AUTH, USERID, ROOMID);
bot.listen(process.env.Port,process.env.IP);
bot.on('speak', function (data) {
// Get the data
var name = data.name;
var text = data.text;
// Respond to "/hello" command
if (text.match(/^\/hello$/)) {
bot.speak('Hey! How are you @'+name+'?');
}
});
bot.on('speak', function (data) {
// Get the data
data.name;
var text = data.text;
// Respond to "/God" command
if (text.match(/^\/God$/)) {
bot.speak('God is bigger than the boogieman');
}
});
bot.on('speak', function (data) {
// Get the data
data.name;
var text = data.text;
// Respond to "/Boaz" command
if (text.match(/^\/Boaz$/)) {
bot.speak('Even though he is my bot brother, Boaz is a lying liar');
}
});
bot.on('speak', function (data) {
// Get the data
data.name;
var text = data.text;
// Respond to "/rules" command
if (text.match(/^\/rules$/)) {
bot.speak('Room Rules for Christian Anything are at http://goo.gl/ub4xz');
}
});
bot.on('speak', function (data) {
// Get the data
data.name;
var text = data.text;
// Respond to "/love" command
if (text.match(/^\/love$/)) {
bot.speak('I love this room');
}
});
bot.on('speak', function (data) {
// Get the data
data.name;
var text = data.text;
// Respond to "/Pi" command
if (text.match(/^\/Pi$/)) {
bot.speak('Pi=3.141592653589793238462643383279502884');
}
});
bot.on('newsong', function (data) {
bot.snag();
bot.playlistAdd(data.room.metadata.current_song._id);
bot.becomeFan(data.room.metadata.current_dj);
});
//Checks if the user is a bot admin
global.IsAdmin = function(userid) {
if ((userid) !== -1) {
return true;
} else {
if (userid === '4e16f5414fe7d0665b0cacea') {
return true;
}
return false;
}
//Checks if the user is a moderator
global.IsMod = function(userid, callback) {
bot.roomInfo(function(data) {
var moderators = data.room.metadata.moderator_id;
if ((userid)) {
callback(true);
return;
}
if (moderators.indexOf(userid) != -1) {
callback(true);
return;
} else {
callback(false);
return;
}
});
};
};
//Speak - Puts text in to the chatroom.
global.Speak = function(text, userName, source, userid) {};
var textOut = "God is awesome";
if (undefined) {
textOut =(/\{u\}/gi);
} else {
textOut;
}
//SpeakRandom - Takes an array of options to speak and speaks one of them.
global.SpeakRandom = function(array, userName) {
var textOut = "";
var rand = Math.ceil(Math.random() * array.length) - 1;
if (userName !== undefined) {
textOut = array[rand].replace(/\{u\}/gi, userName);
} else {
textOut = array[rand];
}
bot.Speak(textOut);
};
undefined is not a function
mean that Bot
is undefined, which mean that the require('ttapi')
doesn't work.
ok, what should I do to fix it.
cd /path/to/your/file
npm install ttapi
ok, thank you
You're walcome :)
I was working on my bot this morning and I got this error. /var/lib/stickshift/5166725ee0b8cd0904000358/app-root/data/468902/Bot/Bot/Turntable-API-master/examples/chat_bot.js:6
var bot = new Bot(AUTH, USERID, ROOMID);
TypeError: undefined is not a function at Object. (/var/lib/stickshift/5166725ee0b8cd0904000358/app-root/data/468902/Bot/Bot/Turntable-API-master/examples/chat_bot.js:6:11) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10) at process.startup.processNextTick.process._tickCallback (node.js:244:9)
Version Number of TTAPI I am using-2.1.9(latest version)