-
Notifications
You must be signed in to change notification settings - Fork 1
4.1 Writing plugins
Ellen Fawkes edited this page Aug 15, 2017
·
1 revision
- All plugins is placed in
plugins/directory - Plugin directory name must be with capitals
- Plugin inital file must be same as plugin dir name, but all chars MUST BE SMALL-CASE with suffix
.js - If you want implement a commands, must be defined by
exports.commands. Command implementation is defined by
exports.<commandName> = function() { ... }- All plugins must defined and initied own logger. Don't use console.log() and etc Logger derives a console
- Plugins have an init function, where is handled at plugin was init!
- Create directory
plugins/<YourPluginName>(with capitals) - Make a first JS file
plugins/<YourPlugin>/<yourplugin>.js - Use this skeleton of plugin:
var PurrplingBot = require("../../purrplingbot.js");
var logger;
exports.commands = [
"mycommand"
];
exports.init = function(pluginName) {
logger = PurrplingBot.createLogger(pluginName); // Init a logger for this plugin
}
exports.mycommand = {
"description": "My awesome command",
"usage": "<arg1> <arg2> [<arg3>]", // Usage it's not mandatory - Only for !help mycommand info
"exec": function(message, tail) {
// exec() is MANDATORY !! Without it is not a valid command.
// TODO: write your command implementation
}
};
// Avoid plugin run standalone
if (require.main === module) {
console.error("This plugin cannot be run standalone! Run 'node purrplingbot.js' instead.");
process.exit(1);
}- Write your plugin code
- Run a purrplingBot