Subscriber Plugin

This plugin is built-in.

This plugin provides the handlers plugin hook from which you can subscribe to messages' and commands' event emitters, amongst others. When write a plugin, this is how you are supposed to subscribe to these events. Each event type has a prefix with exception to the messages event emitter which requires no prefix.

Base Subscriptions

There are four base emitters in Tennu that you can subscribe to.

Prefix Provider Functionality Given
(none) Messages Access to Message events sent from the IRC Server.
! Commands Access to Command events parsed from PRIVMSGs.
action: Action Access to the results of various actions performed by the client.
ctcp: Ctcp Access to CtcpRequest events parsed from PRIVMSGs.

Exports

on, off, once
These three functions take an object where the properties keys are the event names including their prefixes and the property values are the handlers. They follow the same rules as the methods on Node.js's event emitters.
defaultPrefix: Symbol

The symbol passed to the subscribe hook's prefix property to specify that you are adding a default subscriber.

You shouldn't need to use this, since Tennu already uses the default subscriber for messages.

Plugin Hooks

subscribe: {prefix: String, emitter: EventEmitter}

This hook lets you add a new event emitter for the subscriber to dispatch to.

Note: A plugin may only add one subscription. If you need to add more, file an issue. or send a PR to add the functionality.

We recommended that plugins set the prefix as some word related to the plugin followed by a colon. For example, the ctcp plugin subscribes the prefix "ctcp:".

handlers: Object<EventNames, Handler>

Registers each property as an event where the key is the event name and the value is the handler.

const HelloPlugin = {
    name: "hello",
    init: function (_client, _imports) {
        return {
            handlers: {
                "!hello": function (command) {
                    return `Hello ${command.args[0]}!`;
                },

                "ctcp:hello": function (ctcp) {
                    return "Hello!";
                }
            }
        };
    }
};