Skip to content
qshane edited this page Jul 12, 2015 · 5 revisions

Plugins API

Making a plugin for dobby is easy. Simply create a new file in the plugins/ directory. If your plugin is named cuck, name your plugin cuck.js. In the config.toml under the plugins section, you must enable it with cuck = true in order for it to be used by dobby.

Your plugin may optionally provide any of the following exports:

exports.onMessage(msg, dobby)

If dobby sees a message posted in chat, this function is called if it exists. msg is a string containing the message posted in chat.

The following properties are available from the dobby interface variable:

dobby.cid

This is the channel ID that the message was posted in.

console.log("Received message on channel ID " + dobby.cid);

dobby.client_from

This is a Client object for the user which posted the message in chat.

dobby.respond(msg[, cb])

We can use this to respond in the channel we received the message with our own message. msg is a string, but cannot be too long or it will be cut off due to protocol restrictions. If you provide cb(err), it will be called after the message is sent.

dobby.respond("How are you?");

dobby.client_list(cb)

This function will obtain a client list from teamspeak and return it to cb(clients) in the form of a Client array.

dobby.find_clients(partial, cb)

This function is like dobby.client_list, except you provide a (partial) username string, which is matched case insensitive. cb(clients) is provided the filtered list of clients.

dobby.send(cmd, options, cb)

This allows you to manually send commands over server query. cmd is the command name, options is an object containing the fields expected by the protocol. cb(err, response) will be called when it finishes.

dobby.send("channeledit", {cid: dobby.cid, channel_codec_quality: 3}, function(err) {
    if (err) {
        console.warn("error editing channel: " + JSON.stringify(err));
    } else {
        console.log("codec quality was changed to 3");
    }
});

exports.init(dobby)

Sometimes plugins need to initialize behavior, like repeatedly getting the clientlist every 5 seconds for the duration of the program. dobby will contain some helper functions to allow you to do this, like exports.onMessage.

exports.config(cfg)

Sometimes plugins need a secret key, like a database password or API key. These should be stored in the config.toml and provided as part of the plugin, like so:

...

[plugins.cuck]
on = true
api_key = "81NJX781OP305JM1045N28GF"

...

The exports.config function you provide is called during plugin initialization, when the bot starts up. In this example, we store a secret in a variable in the above scope, so that our exports.onMessage or other callbacks can access it.

var secret = "";

exports.config = function(cfg) {
    secret = cfg.api_key;
}

Client

This is an object which allows you to interact with, and receive information for, a Client in teamspeak. By the time you obtain one of these objects, it is possible that a client has disconnected, so do not expect to store this object for long periods of time.

Client.is_admin(cb)

This function will call cb(err, is_admin) where is_admin is a boolean describing whether or not the client is an admin in the configuration file.

Client.get_name(cb)

This function will get the client's name and call cb(err, name) when it has finished.

Client.get_cid(cb)

This function will get the channel ID the client is in and call cb(err, cid) when it has finished.

Client.get_clid(cb)

This function will get the client ID and call cb(err, clid) when it has finished.

Client.get_uid(cb)

This function will get the client's UID and call cb(err, uid) when it has finished.

Client.get_ip(cb)

This function will get the client's IP address and call cb(err, ip) when it has finished.

Client.private_message(msg, cb)

This function will send a private message to the user and call cb(err) when it has finished.

Client.is_admin(cb)

This function will determine if this user is an administrator and call cb(err, is_admin) when it has finished.

Client.disable_updates()

Many of the above functions automatically update client information. If you're going to be calling many of them, running Client.update() and then Client.disable_updates() will speed up the process.

Client.update(cb)

This will update the client's information and call cb(err) when it has finished.