Skip to content

4.1 Writing plugins

Ellen Fawkes edited this page Aug 15, 2017 · 1 revision

Plugin rules

  • 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 new own plugin

  1. Create directory plugins/<YourPluginName> (with capitals)
  2. Make a first JS file plugins/<YourPlugin>/<yourplugin>.js
  3. 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);
}
  1. Write your plugin code
  2. Run a purrplingBot

Clone this wiki locally