Skip to content

Getting Started

chrishayesmu edited this page May 11, 2016 · 5 revisions

It is recommended that you look at or fork the example project at DubBotBaseExample while following this wiki.

Step 1: NPM setup

In your package.json file, add dubbotbase to your dependencies section:

{
    ...
    "dependencies": {
        ...
        "dubbotbase": "*"
    }
}

..and then run npm install. (But please, pick a real version and don't use *.)

Step 2: Create your entry point file

The next step is to create a file that starts up the bot. This is extremely simple with DubBotBase. You can add the following code in a file located at src/main.js:

var DubBotBase = require("dubbotbase");

DubBotBase.start(__dirname + "/..");

The above code will start the bot and tell it which directory should be considered the root directory for your bot. This impacts where it will look for other modules to automatically load for functionality, as well as where the bot will look for configuration files.

Running this code will fail right now; we need to add some configuration first.

Step 3: Set up your configuration

The base functionality in DubBotBase is configuration-driven. Configuration is automatically read from the config/ directory, which should be located in the root directory specified by your src/main.js. There are only three required configuration keys:

  • botEmail: This is the email address your bot uses to log in to dubtrack.fm. Only email login is supported.
  • botPassword: This is the password your bot uses to log in to dubtrack.fm.
  • roomName: This is the name of the room you want your bot to connect to, though "room" is not entirely accurate. When you join a dubtrack.fm room, the URL looks like https://dubtrack.fm/some-room-name. It is the some-room-name which you should supply here. Room names can change, but this part of the URL never will.

Everything should be defined in your JSON configuration file, under the DubBotBase namespace:

{
    "DubBotBase":
    {
        "botEmail" : "mybotemail@gmail.com",
        "botPassword" : "mypassword",
        "roomName" : "some-room-name"
    }
}

Note that these are not the only allowed configuration keys, they're just the only ones required by the framework. You can add any additional keys you want, and they'll be made available to your bot as part of the config object passed around. However, any config key in the DubBotBase namespace is reserved, and if you add keys which conflict with this, you may find your bot not working or behaving strangely in future versions. You can find an up-to-date list of configuration keys here.

At this point, you've set up enough to run the bot. Just run your src/main.js file and watch the bot get going.

Step 4: Add some functionality

(While this step is optional to just getting the bot running, you aren't going to see a whole lot going on without writing some code here. But you can skip this just to test your first-time setup.)

Functionality in DubBotBase is automatically picked up based on files in the following directories:

  • commands: Modules in here expose commands which dubtrack.fm users in your room can take advantage of.
  • event_listeners: Modules in here listen to events emitted by the dubtrack.fm framework, and take some action in response. They tend to update global state, store info in a database, or talk to your room's users, but there's no limit to what they can do.

As with the config/ directory, commands/ and event_listeners/ are looked for automatically relative to the base directory you provide when starting up the bot.