Plugin Factory

The plugin factory structure is what tennu-plugins, the plugin system for tennu, uses to install a plugin into a bot.

Do not be scared that this is called a factory. It's just an object that holds the real [plugin](plugin) constructor and static metadata.

Properties

The only required property to the Plugin factory object is the init method, though you should also include the name.

Property Description
init (client: Client, imports: [Object<PluginName, PluginExportsObject>)]) -> Plugin

The actual function that constructs an actual Plugin. It takes as parameters the client the plugin will be installed into and a dictionary to the plugin exports of the plugins that the plugin depends on.
name String

Usually inferred, this is required when installing a plugin via Client::initializePlugin. Since Client::use and the configuration object exist, you shouldn’t need that method or this property. It exists for posterity’s sake if somebody wants to use tennu-plugins for their own framework without wanting the magic provided by its use method.
role String | undefined

The role that a plugin provides. Basically, if a plugin exports object has an interface, the name of that interface becomes the name of the role. One example is tennu-admin, which exports the admin interface.
requires [String] | undefined

The list of plugins that this plugin relies on by name.
requiresRoles [String] | undefined

The list of roles that this plugin relies on by name.

Static Hooks

Just like a Plugin has hooks (such as e.g. handlers), a PluginFactory also has hooks. Hooks in the PluginFactory are called Static Hooks while hooks in the Plugin are called Instance Hooks.

Right now, Tennu provides one static hook, configDefaults, though other plugins can add more.

Template

For your convenience, here is a template for making plugins.

Things in ALL CAPS should be replaced, not kept in ALL CAPS

const OTHER_MODULES = require("...");

// Constant definitions goes here.

const PLUGIN_NAME_FACTORY = {
    name: "PLUGIN_NAME",

    configDefaults: {
        "PLUGIN-FOO": undefined
    },

    init: function (client, imports) {
        // Pull imports into their own variables.
        const import = imports["import"];

        // Any per-instance initialization goes here.

        return {
            handlers: {
                privmsg: function (message) {

                },

                "!command": function (message) {

                }
            },

            help: {
                "command": [
                    "!command",
                    "",
                    "Help for !command"
                ]
            },

            commands: ["command"]
        };
    },

    role: undefined,
    requires: [],
    requiresRoles: []
};