Skip to content

4.2 Getting a configuration

Ellen Fawkes edited this page Sep 3, 2017 · 2 revisions

Getting a configuration (not only) in plugins

Get configuration

RECOMMENDED

In your plugins get a configuration via PurrplingBot.getConfiguration()

Example

/* plugins/MyP/lugin/myplugin.js */
var PurrplingBot = require("../../purrplingbot.js");
const CONFIG = PurrplingBot.getConfiguration();

var myPluginConf = CONFIG.myPlugin;

// Do your stuff here (Write init(), create logger and etc)

Load configuratiuon via Configurator lib

EXPERT MODE and live on edge

Configuration is loading by Configurator lib. PurrplingBot use it and propagate loaded config by method getConfiguration() It's a RECOMMENDED for use!

If you want use low level configuration loading, then use a internal library Configurator.

Example

// Load configuration (loads all in @imports)
const Configurator = require("./lib/configurator.js");
var config = {};

try {
  config = Configurator.loadConfiguration("./config.json");
 } catch (err) {
  logger.error("*** Configuration failed to load! Check the config file.");
  logger.error(err);   
  process.exit(6);
}

// Get a raw configuration file (NOT load @imports)
var rawConf = readConfigFile("./myConf.json");
if (!rawConf) throw new Error("Config can't be loaded!");

logger.dir(rawConf.foo); // export DEBUG=1
Clone this wiki locally