Skip to content
Bibliofile edited this page Jul 19, 2019 · 3 revisions

OUTDATED: Not supported in latest version of the bot.

As of version 6.0.0, hooks are used to listen to and respond to events within the bot. A complete list of available hooks can be found here.

Hook events can be sent by an extension. They do not need to be created before being checked.

The hook object is available through extension.hook. It contains 4 methods.

hook.listen(key, callback)

Use this method to begin listening for the key event. When the key event is called, the callback function will be called with any arguments provided by the calling code.

hook.remove(key, callback)

Use this method to remove a listener for key. Callback must be the same function provided in hook.listen. If an anonymous function is passed, then the listener cannot be removed.

hook.check(key, ...args)

Calls any functions listening to key with the supplied arguments.

hook.update(key, initial, ...args)

Calls any functions listening to key in an undefined order. The first argument passed will be the initial argument, followed by any additional provided arguments. The returned value from the callback will be used as the initial value for the next called callback. This method will return the value returned from the last callback, or the initial value if there are no listeners.


Hooks can be best understood through experiments. With the bot loaded, paste this code into your browser's console.

hook.listen('hello', function(name) { console.log("Hello " + name + "!"); });
hook.check('hello', 'Stranger');

As you can see, when you called the event hello, the listening function was called. Experiment with this, perhaps by changing Stranger to your own name.

You can also create listeners with more than one argument. Try out the following code:

hook.listen('hello2', function(name, age) { console.log("Hello " + name + "! You are " + age); });
hook.check('hello2', 'Stranger', 42);

Clone this wiki locally