ward / irc-butler

IRC bot for my needs
3 stars 1 forks source link

General way to handle configuration for plugins #23

Open ward opened 7 years ago

ward commented 7 years ago

Twitter and strava plugins require API access information. This should be somehow defined in the plugin list but requires some rethinking of that part of the configuration.

ward commented 7 years ago

Retake-name could also use specific configuration: how often to check to retake the name.

ward commented 7 years ago

Would also want some standard functions to check for the (required) presence of these configuration values.

Q: If not present, stop loading the bot entirely or just abandon loading that specific plugin? If the latter, is this something that can just be halted within the plugin?

ward commented 7 years ago

Concerns this part

let stravaconfig = config.get('bot.strava');
for (let key in stravaconfig) {
  if (stravaconfig[key] === null || stravaconfig[key] === undefined) {
    throw new Error('Tried to load strava plugin, but credentials are not present: ' + JSON.stringify(stravaconfig));
  }
}
ward commented 7 years ago

Along the lines of what a plugin should then put near the start of its script:

let account = plugin.requires('account');
let time = plugin.accepts('time', 'some default value');

If a requires() call fails (turns out there is no such information), then loading the script should halt, an error should be printed, but the bot should carry on without that plugin.