Developing Bots

Requirements

Aside from the standard development stuff, a few things are needed to develop apps or bots with this framework.

A TypeScript compiler is absolutely required. Without this, the entire framework simply wont build. If you don't know TypeScript but do know JavaScript, this is not an issue. TypeScript only extends JavaScript; all JavaScript is valid TypeScript, so you can develop like normal while still using this framework.

Along with the TypeScript compiler, you need a tsconfig.json file in your project directory. Exactly what goes in this is largely up to you. Use the various ones in the hosted apps and bots as reference.

Then, as long as everything compiles without error, you will have a viable bot for upload.

Includes

The entire CB API declarations should be included in your tsconfig.json. There's no overhead these add, just include them all.

Within /Common there is a collection of TypeScript files for use, without any ties to a specific app or bot. While some of these have dependencies, there is no requirement to include any or all of these; pick what you want to use.

Necessary Stuff

The common files are not magic, and it is necessary to write some "glue" to make everything you've included work.

Parser

The command parser needs to be glued together for each app or bot. Luckily, this is not difficult as it follows a common pattern. Within cb.onMessage(), for each module you wish to expose commands:

if (!validCommand)
    validCommand = <<Module>>.tryParse(<<Message>>);

Where <<Module>> is the full name of the module, such as dozer or tipmenu.special and where <<Message>> is the message object, likely by name. validCommand should be defined as a Boolean, and may be replaced with alternative schemes.

Help

Each module has a function to print out help, but you may want to collectively group them. Doing this requires writing a tryParse() function and collecting all help() functions inside of it. This tryParse() should be called in the same way and location as all others.

Other Hooks

For everything else, no single and simple guideline can be described. Call what you need to, where you need to.

Recommendations

Asides from a settings_choices.ts file specific to your bot, it is a good idea to make a matching settings.d.ts to conveniently expose the resulting object CB will create at launch.

Initialization is done in a file called zinit.ts in all the hosted apps and bots. It is recommended to keep to this convention. The name encourages the TypeScript compiler to keep the file at the end of the output script.