#Turntable API
A simple nodejs wrapper for the turntable API
npm install ttapi
Find your AUTH, USERID and ROOMID informations with that bookmarklet.
This bot responds to anybody who writes "/hello" in the chat.
var Bot = require('ttapi');
var bot = new Bot(AUTH, USERID, ROOMID);
bot.on('speak', function (data) {
// Respond to "/hello" command
if (data.text.match(/^\/hello$/)) {
bot.speak('Hey! How are you '+data.name+' ?');
}
});var Bot = require('ttapi');
var AUTH = 'auth+live+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var USERID = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var ROOMID = 'xxxxxxxxxxxxxxxxxxxxxxxx';
var bot = new Bot(AUTH, USERID);
bot.on('ready', function (data) { bot.roomRegister(ROOMID); });
bot.on('roomChanged', function (data) { console.log('The bot has changed room.', data); });
bot.on('speak', function (data) { console.log('Someone has spoken', data); });
bot.on('update_votes', function (data) { console.log('Someone has voted', data); });
bot.on('registered', function (data) { console.log('Someone registered', data); });var Bot = require('ttapi')
, repl = require('repl');
var bot = new Bot(AUTH, USERID, ROOMID);
repl.start('> ').context.bot = bot;
// ...REPL allows you to dynamically call the bot functions and modify his variables during his execution.
bot.debug = true;That will print on the terminal all the data that you get and all the data that you send.
https://no.de/ : Free hosting for nodejs projects.
Here are some examples of the data that you'll receive from those events.
Triggered when a socket opens a connection.
Triggered when the bot receives a tcp message.
Triggered when a socket closes its connection.
Triggered when the bot receives an http request.
on('roomChanged', function (data) { })
Triggered when the bot enters a room.
on('registered', function (data) { })
Triggered when a user enters the room.
on('deregistered', function (data) { })
Triggered when a user leaves the room.
on('speak', function (data) { })
Triggered when a new message is sent via the chat.
on('endsong', function (data) { })
Triggered at the end of the song. (Just before the newsong/nosong event)
The data returned by this event contains information about the song that has just ended.
on('newsong', function (data) { })
Triggered when a new song starts.
on('nosong', function (data) { })
Triggered when there is no song.
on('update_votes', function (data) { })
Triggered when a user votes.
Triggered when a user is booted.
Triggered when a user changes his name/info.
on('add_dj', function (data) { })
Triggered when a user takes a dj spot.
on('rem_dj', function (data) { })
Triggered when a user leaves a dj spot.
on('new_moderator', function (data) { })
Triggered when a user is promoted to moderator.
on('rem_moderator', function (data) { })
Triggered when a user loses his moderator title.
on('snagged', function (data) { })
Triggered when a user queues the currently playing song.
on('pmmed', function (data) { })
Triggered when the bot receives a private message.
Start a tcp server.
Start an http server.
Get the turntable server time.
Get 20 rooms.
Get the location of your friends/idols.
Get the location of a user. If allInformations is true, you'll also receive the information about the room and the user.
This function will make the bot become a fan of the user.
Get your favorite rooms.
Add a room to your favorite rooms.
Remove a room from your favorite rooms.
Register in a room.
Deregister from the current room.
Get the current room information. Do not include song log if 'extended' is false.
Broadcast a message in the chat.
Boot a user.
Alias of bootUser().
Add a moderator.
Remove a moderator.
Add yourself as a Dj.
Remove a Dj.
Skip the current song.
Alias of stopSong().
Vote for the current song.
Alias of vote('up').
Authenticate the user.
Get the current user's information.
Get the list of who you've become a fan of.
Get a user's profile.
Modify your profile. Any missing properties from the 'profile' object will be replaced with the current values.
profile:obj (required)name:string (optional)twitter:string (optional)facebook:string (optional)website:string (optional)about:string (optional)topartists:string (optional)hangout:string (optional)
callback:fn (optional)
bot.modifyProfile({ website:'http://ttdashboard.com/', about:'My bot.' }, callback);Modify your laptop.
Modify your name.
Set your avatar.
Fan someone.
Unfan someone.
Snag the song.
This function will not add the song into the queue.
Send a private message.
Get the private conversation history.
Set your current status.
Get all information about a playlist.
playlistName(optional) default:defaultcallback(required)
bot.playlistAll(callback);
bot.playlistAll(playlistName, callback);Add a song to a playlist.
playlistName(optional) default:defaultsongId(required)index(optional) default:0callback(optional)
bot.playlistAdd(songId);
bot.playlistAdd(songId, idx);
bot.playlistAdd(songId, callback);
bot.playlistAdd(songId, idx, callback);
bot.playlistAdd(playlistName, songId, idx);
bot.playlistAdd(playlistName, songId, callback);
bot.playlistAdd(playlistName, songId, idx, callback);
bot.playlistAdd(false, songId, callback); // Backward compatibility
bot.playlistAdd(false, songId); // Backward compatibilityRemove a song on a playlist.
playlistName(optional) default:defaultindex(optional) default:0callback(optional)
bot.playlistRemove();
bot.playlistRemove(index);
bot.playlistRemove(index, callback);
bot.playlistRemove(playlistName, index);
bot.playlistRemove(playlistName, index, callback);Reorder a playlist. Take the song at index indexFrom and move it to index indexTo.
playlistName(optional) default:defaultindexFrom(required) default:0indexTo(required) default:0callback(optional)
bot.playlistReorder(indexFrom, indexTo);
bot.playlistReorder(indexFrom, indexTo, callback);
bot.playlistReorder(playlistName, indexFrom, indexTo);
bot.playlistReorder(playlistName, indexFrom, indexTo, callback);