-
Notifications
You must be signed in to change notification settings - Fork 6
Extending Gord via the scripting interface
Gord 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 gord
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
If a function is marked with UNSTABLE API
, that means the return values or even parameters might change at a later point in time.
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 set up the global state of your script. This
is useful, as it will avoid having to always write lazy initialization
code or even keep repeating certain things every time a callback has
been executed.
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 going to be a string that is the content of the message that the user sent to the channel.
You can modify the message by returning a different message
value.
If you want the message to remain unchanged, just return the same message
value.
This callback gets called whenever a message is received in any guild or DM.
Parameters
Name | Description |
---|---|
message | An object representing the received message. |
Return value
None
This callback gets called whenever a message is edited in any guild or private chat.
Parameters
Name | Description |
---|---|
message | An object representing the edited version of the message. |
Return value
None
This callback gets called whenever a message is deleted in any guild or private chat.
Parameters
Name | Description |
---|---|
message | An object representing the deleted message. |
Return value
None
This function can be used to trigger a notification in the users system. On Windows 10 for example, this would show a so called "toast".
Parameters
Name | Description |
---|---|
title | The title of the notification. |
text | The main content of the notification. |
Return value
None
This function can be used to print text to the cordless console.
Parameters
Name | Description |
---|---|
text | The text, which will be printed to the console. |
Return value
None
This function can be used to print text to the cordless console and also appending a newline.
Parameters
Name | Description |
---|---|
text | The text, which will be printed to the console. |
Return value
None
This function 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
.
Parameters
None
Return value
A string representing the ID of the currently selected guild.
This function returns the ID of the currently selected channel. Selecting meaning the channel that the cordless user is currently viewing.
Parameters
None
Return value
A string representing the ID of the currently selected (loaded) channel