Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Extending Cordless via the scripting interface

Marcel Schramm edited this page Feb 22, 2020 · 8 revisions

Cordless has a very basic scripting interface that exposes predefined events and offers some globally callable functions.

Scripts can simply be dumped into the subfolder scripts of the cordless configuration folder. Every file ending on .js will be parsed as a cordless script. Whether the file is in a subdirectory or not, doesn't matter at all.

Scripts are running synchronized. There can't be two calls to one script at the same time, since scripts can contain global state. A script only gets called on a specific event if it actually contains the given callback for that event.

A simple example can be found here: Kaomoji

Available callbacks

init

The init callback is a special callback that will only be called once and then be removed from the scripting engine. Therefore you can't ever manually call this method, as it will result in an undefined method error. The method takes no parameters and doesn't return anything. It can be used in order to setup the global state of your script. This is useful, as it will avoid having to always write lazy initialisation code or even keep repeating certain things every time a callback has been executed.

onMessageSend

Gets called as soon as the cordless user submits a message for sending and allows for manipulating the message to be sent.

Parameters

Name Description
message The text, which was meant to be sent to the current channel.

Return value

The return value is just a single string which will be the message that's gonna be sent in place of the value of the message parameter. If you want the message to remain unchanged, just return the message parameter.

onMessageReceive

TODO

onMessageDelete

TODO

Available global functions

triggerNotification

TODO

printToConsole

TODO

printLineToConsole

This function can be used to print text to the cordless console.

getCurrentGuild

This function can be called at any time and returns the ID of the currently selected guild. Note, that the currently selected channel must not be part of the selected guild and therefore might differ from the guild in the channel returned by getCurrentChannel.

This function doesn't have any parameters.

getCurrentChannel

This function can be called at any time and returns the ID of the currently selected channel.

This function doesn't have any parameters.

Clone this wiki locally