Modules are written in javascript with the .js extension. To install, put the code into a text file, name it [modulename].js, and put it into the /modules/ folder. Restart KoalaBot.
Some example modules:
You can find more modules and get help in creating them at /r/koalabot.
Adds a command, makes it lower case. It will call the function name you send it. The function will be given these parameters: params (array), from (string), mod (boolean), subscriber (boolean)
Parameters
off, all,
reg, sub, mod, or bot. Off disables the command, even for the streamer. All is self explanatory. Reg is for regulars and above (sub, mod, bot). Sub is for subscribers and above (mod, bot). Mod
is for moderators and above (bot). Bot is for the bot itself AND the streamer.
Returns boolean - True if success, false if fail.
Example
apiAddCmd('test', 'commandTestThing', 'all', 'This is a test command!');
function commandTestThing(params, from, mod, sub) {
// do something when the command is used, like...
apiSay( 'from: ' + from + ', params: ' + params.join(', ') );
}
Changes the access control of a command.
Parameters
Returns boolean - True if success, false if fail.
Adds a module to the dropdown and creates a page. If the module only adds commands and doesn't require a user interface, this doesn't need to be used.
Parameters
Returns
boolean - The id of the page to $(id).prepend /
$(id).html / $(id).append .
Example
// Making the tab
var _myTab = apiAddTab('moduleTest');
$(_myTab).html( `<div class="row-fluid">
<div class="col-sm-12">
Hello World
</div>
</div>` );
Writes to the chat. It outputs as [+] to show it's a module rather than [!] that the base bot uses.
Parameters
Only outputs to the chatlog and your chat window, but does not send a chat message for others to see. It is used to notify the streamer of things.
Parameters
Gets the path to the mods folder, ex: C:\bot\mods\
Returns string - The path to the mods folder, including the trailing slash
Gets the channel name, which is also the streamer's username.
Returns string - The channel name.
Gets the bot's username.
Returns string - The bot name.
Gets the unit name for points. For example, "gold" or "cats".
Returns string - The points unit.
Gets the number of points a user has.
Parameters
Returns integer - Null if not found, otherwise the amount of points of the user.
Gets the number of minutes a user has been in the stream while the bot is also in the stream.
Parameters
Returns integer - Null if not found, otherwise the amount of minutes the user has been in the stream.
Sets the points a user has. This is not for adding or subtracting points.
Parameters
Returns integer - Null if not found, otherwise the new amount of points the user has.
Modifies the points a user has by a relative amount. Using this command with points at 5, for example, would add 5 points to the user's total.
Parameters
Returns boolean - Null if not found, otherwise the new amount of points the user has.
Example
// Adding 5 points to a user
apiModPoints('skhmt', 5);
// Subtracting 7 points from a user
apiModPoints('skhmt', -7);
Opens a file in the \mods\ directory.
Parameters
Returns string - The file contents, null if it doesn't exist.
Example
// Loading a settings object
var _mySettings = JSON.parse( apiOpenFile( 'modExampleSettings.ini' ) );
// Loading a file with just text
var _myText = apiOpenFile( 'modExampleOutput.txt' );
Appends a new line of text to the end a file in the \mods\ directory. If a file isn't found, it will automatically be created, then appended to.
Parameters
Returns boolean - True if success, false if fail.
Writes a file in the \mods\ directory. This will completely over-write an existing file.
Parameters
Returns boolean - True if success, false if fail.
Example
// Saving a settings object
apiWriteFile( 'modExampleSettings.ini', JSON.stringify( _mySettings ) );
// Writing a file with a line of text
apiWriteFile( 'modExampleOutput.txt', 'Hello World!' );
Gets an array of the recent events, in format:
[ { "time": (integer milliseconds since midnight of January 1, 1970), "type": (string), "text": (string) }, ... ]
Type will be SUB, HOST, FOLLOW, or anything that a module adds
Returns array - The most recent events in the above format.
Adds to the recent events array. Recent events is used to send to a page via ajax, most likely.
Parameters
SUB, HOST, and FOLLOW for those events. Use your own type if you need to.
SUB, HOST, and FOLLOW, it's only the username.
Adds a global hotkey. Supported keys: A-Z, 0-9, Comma, Period, Home, End, PageUp, PageDown, Insert, Delete, Arrow keys ( Up, Down, Left, Right ) and the Media Keys ( MediaNextTrack, MediaPlayPause, MediaPrevTrack, MediaStop )
Combine them with Ctrl, Alt, or Shift. Ex: Ctrl+Alt+Comma
On OSX, Ctrl is command. These global hotkeys will block the normal function of those keys.
Parameters
Returns object - Use to set functionality of the hotkey.
Example
var _ctrlAltComma = apiHotKey( 'Ctrl+Alt+Comma' );
_ctrlAltComma.on( 'active', function() {
alert( 'CTRL + ALT + Comma has been pressed!' );
} );
Creates/loads a sqlite database. This is an object.
Parameters
Functions
SELECT query on the database. Returns an object in the format:
{ "array": [ ... ], "table": "<table> ... </table>" }
CREATE TABLE, INSERT INTO, or DELETE FROM query. Returns true if success, false if fail.
Example
// Open or create the db moduleTestDB.sqlite
var _db = apiDB( apiGetPath() + 'moduleTestDB.sqlite' );
// Creates a table with columns: id, content
_db.run( 'CREATE TABLE test_table (id INTEGER PRIMARY KEY, content TEXT);' );
// Insert some test values...
// Using NULL for the primary key automatically sets it as the next highest integer
_db.run( 'INSERT INTO test_table VALUES (NULL, "hello world");' );
_db.run( 'INSERT INTO test_table VALUES (NULL, "hello darkness my old friend");' );
_db.run( 'INSERT INTO test_table VALUES (NULL, "hello moto");' );
// Deleting 'hello moto'
_db.run( 'DELETE FROM test_table WHERE content = "hello moto";' );
// Outputting a HTML table
$('#outputArea').html( _db.sel( 'SELECT * FROM test_table;' ).table );
// Outputting the array
$('#outputArea').append( JSON.stringify( _db.sel( 'SELECT * FROM test_table;' ).array ) );
// Saving
_db.write();