A generic API for creating Plug.dj bots
Just grab it from npm, or optionally use the lastest version for github
npm install plugapi
To connect, do this!
var AUTH = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx=?_expires=xxxxxxxxxxxxxxxxxx==&user_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx='; // Put your auth token here, it's the cookie value for usr
var ROOM = 'coding-soundtrack';
var bot = new PlugAPI(AUTH);
bot.connect();
bot.on('connected', function() {
bot.joinRoom('coding-soundtrack');
})
You can also pass the room directly to connect to save SO MUCH TIME
bot.connect(ROOM);
Here are some bots using this API. Check out how they did it!
Have a bot that uses the API? Let me know!
You can listen on essentially any event that plug emits. Many of the events also emit an alias event named after the ttapi version
// basic chat handler to show incoming chats formatted nicely
bot.on('chat', function(data) {
if (data.type == 'emote')
console.log(data.from+data.message)
else
console.log(data.from+"> "+data.message)
})
Here's an example for automatic reconnecting on errors / close events!
var reconnect = function() { bot.connect('coding-soundtrack'); };
bot.on('close', reconnect);
bot.on('error', reconnect);
Here's a list of events:
data:
fromID: 'user id'
message: 'message text'
from: 'username'
type: 'message type'
chatID: 'chat id'
type: 'chat'
Example:
{ data:
{ fromID: 'xxxxxxxxxxxxxxxxxxxxxxxx',
message: 'hello world',
from: 'mnme',
type: 'message',
chatID: 'xxxxxxxxxx' },
type: 'chat' }
data:
id: 'user id'
type: 'userLeave'
Example:
{ data: { id: 'xxxxxxxxxxxxxxxxxxxxxxxx' }, type: 'userLeave' }
data:
username: 'username'
status: 0/1/2/3/4/5
fans: fans
listenerPoints: points from listeners
language: 'language'
avatarID: 'bud03'
id: 'xxxxxxxxxxxxxxxxxxxxxxxx'
curatorPoints: points from curators
djPoints: points from DJing
type: 'userJoin'
Example:
{ data:
{ username: 'mnme',
status: 0,
fans: 3,
listenerPoints: 164,
language: 'en',
avatarID: 'bud03',
id: 'xxxxxxxxxxxxxxxxxxxxxxxx',
curatorPoints: 0,
djPoints: 76 },
type: 'userJoin' }
sorry, only saw one time :(
data:
vote: 1/0
id: 'user id'
type: 'voteUpdate'
Example:
{ data: { vote: 1, id: 'user id' },
type: 'voteUpdate' }
data:
id: 'user id'
type: 'curateUpdate'
Example:
{ data: { id: 'xxxxxxxxxxxxxxxxxxxxxxxx' },
type: 'curateUpdate' }
data:
currentDJ: 'user id'
djs: [ [Object], [Object], [Object], [Object], [Object] ]
mediaStartTime: 'start time'
media:
title: 'song title'
format: 'x'
author: 'song author'
cid: 'xxxxxxxx'
duration: duration in seconds
id: 'format:cid'
playlistID: 'playlist id'
earn: true/false
historyID: 'id for song history'
type: 'djAdvance'
Example:
{ data:
{ currentDJ: 'xxxxxxxxxxxxxxxxxxxxxxxx',
djs: [ [Object], [Object], [Object], [Object], [Object] ],
mediaStartTime: '2012-11-28 21:12:28.674382',
media:
{ title: 'Freefire - Dataloss (Darth & Vader Remix)',
format: 'x',
author: 'Mateus Rossetto',
cid: 'xxxxxxxx',
duration: 332.935,
id: 'x:xxxxxxxx' },
playlistID: 'xxxxxxxxxxxxxxxxxxxxxxxx',
earn: true,
historyID: 'xxxxxxxxxxxxxxxxxxxxxxxx' },
type: 'djAdvance' }
data:
plays: times the dj played a song, id: 'user id'
plays: times the dj played a song, id: 'user id'
plays: times the dj played a song, id: 'user id'
plays: times the dj played a song, id: 'user id'
plays: times the dj played a song, id: 'user id'
type: 'djUpdate'
Example:
{ data:
[ { plays: 2, id: 'xxxxxxxxxxxxxxxxxxxxxxxx' },
{ plays: 13, id: 'xxxxxxxxxxxxxxxxxxxxxxxx' },
{ plays: 7, id: 'xxxxxxxxxxxxxxxxxxxxxxxx' },
{ plays: 10, id: 'xxxxxxxxxxxxxxxxxxxxxxxx' },
{ plays: 0, id: 'xxxxxxxxxxxxxxxxxxxxxxxx' } ],
type: 'djUpdate' }
There aren't that many functions implemented yet, and I'm too lazy to document each one yet (HALP?)....
Here's a list:
Connects to plug.dj and optionally joins a room.
string (optional)
The name of the room to join after succesful connection.
Join a room on plug.dj
string (required)
The name of the room to join.
callback (optional)
This is not a parameter!
bot.joinRoom('coding-soundtrack');
Sends a Message in the Chat.
string
The Message to send.
This is not a parameter!
bot.chat('Hello World!');
Woots the actual song.
callback (optional)
This is not a parameter!
bot.woot();
Mehs the actual song.
callback (optional)
This is not a parameter!
bot.meh();
Vote on the actual song with a string.
string (required)
Either 'up' or 'down', calls the appropriate function (woot() or meh()).
callback (optional)
This is not a parameter!
bot.vote('up'); //woot the song
bot.vote('down'); //meh the song
Change actual room information. Only available if you are the host.
string (required)
A (new) name for the room.
string (required)
The rooms description.
callback (optional)
This is not a parameter!
bot.changeRoomInfo('Hello World', 'This is a new description for my room.');
If you are in a room and you are host, you can change the room options with this function.
boolean (required)
Toggles the booths state (locked or unlocked).
boolean (required)
Is there a waitlist in this room?
integer (required)
Maximum Plays per DJ.
integer (required)
Limit DJs on the booth to this number (usually 5).
callback (optional)
This is not a parameter!
bot.changeRoomOptions(false, false, 1, 5);
Joins the DJ booth if there is a free place.
callback (optional)
This is not a parameter!
bot.joinBooth();
Leave the DJ booth.
callback (optional)
This is not a parameter!
bot.leaveBooth();
Removes a DJ from the DJ booth if possible. The user has to be in the booth and you need the permission to remove DJs from the booth.
callback (optional)
This is not a parameter!
bot.removeDJ('xxxxxxxxxxxxxxxxxxxxxxxx');
Skips the current song. You need to be DJ or have the permission to skip a song.
callback (optional)
This is not a parameter!
bot.skipSong();
Returns an object containing all the users currently in the room at the moment of calling. Identical to Plug.DJ's API.getUsers()
Returns array containing ambassadors currently in the room
this is a list of avatar names that can be used in user.set_avatar
You can set your own custom logger for the API to use when it logs important events, such as errors or stack traces from the server.
The logger object must have a function called "log" that takes any number of parameters and prints them.
var prompt = new Prompt();
bot.setLogObject(prompt);