Managers
About Managers
Managers, like plugins, are external features that are loading into Disnode and gives bots their functionality. Disnode acts a importer and manager to these Managers, but the Managers handle all the core Features.
Manager Types
Managers can both be 'Core' or '3rd Party'.
CORE: Core Managers are those that are included in Disnode. All you have to do is add them to your bot!
3rd Party: 3rd Party Managers are those created and imported by npm externally. These require you to feed Disnode a path. Although popular, well-coded, or just AWESOME managers can be added to Core!
Manager Configs
Managers come with default configs and commands. If your bot config does not contain a config for a manager, the default config is copied and saved in your bot config. This manager config contains message responses (Responses used when responding inside Disnode), Commands for the Managers, and other options.
ALL SETTINGS INCLUDING COMMANDS ARE EDITABLE IN YOUR BOT CONFIG!
Using Managers
Core Managers
Run Down
To use a Core manager in your bot all you need to know is it's name and options. The name is used through out Disnode to reference it and options are just options you can feed it. (EX: Command Prefix for Command Handler, or Max Volume for AudioPlayer). All the default functionality is imported so you're good to go! Acorse you can edit as you please in your bot's config file.
Code
testBot.addManager({name:"CommandHandler", options:{prefix: "!"}});
The Example above imports the Command Handler managers and sets the option for prefix. Note that no path is required since its located inside Disnode like all Core Managers;
3rd Party Managers
Run Down
3rd Party Managers are almost as simple as they share the same code as Core Managers, but they are located externally. After you import a 3rd Party Manager, you can load it the same way, although you will also need to know the path.
Code
testBot.addManager({name:"ThirdPartyManager",path:"./3rdPartyManager.js", options:{prefix: "!"}});
The Example above imports a 3rd party manager from the path and sets the option for prefix.
Using Managers
By Default your managers should be all set to go. The default commands have be imported by default into your bot's config and the plugin has been initialized. Although if you choose to access Managers in code its quiet simple. You can reference managers by just referring to .. Thats it! Note the name of the object is the same name you used to add it!
Example:
testBot.ConfigManager.someFunction();
//or
testbot.ThirdPartyManager.someFunction();
Writing Managers
To write managers you can first start off using the template below. The options object is a object that contains the options passed into on creation and a reference to Disnode. (options.disnode). All you have to do it right the class, add defaultConfig, and export it!
Example Manager
"use strict"
class TestManager{
constructor(options){
this.defaultConfig = {
defaultSaying: "Default Saying",
responses:{
printSay: "[Sender] Says: [Saying]"
},
commands:[
{
cmd: "testManager",
run: "cmdTest",
context: "TestManager",
usage: "testManager",
desc: "Default Manager Test Command"
}
]
}
var self = this;
//Created Class Varables for Disnode and Options
self.disnode = options.disnode;
self.options = options;
// Loads Config.
self.config = self.disnode.config.TestManager;
//Defaults if saying isn't provided
if(options.saying){
self.saying = options.saying;
}else{
self.saying = self.config.defaultSaying;
}
}
cmdTest(parsedMsg){
var self = this;
var parse = self.disnode.parseString;
//Adds Shortcut for Saying
var customShortCuts = [{shortcut:"[Saying]", data: self.saying}];
self.disnode.bot.sendMessage(parsedMsg.msg.channel,
parse(self.saying,parsedMsg,customShortCuts));
}
}
module.exports = TestManager;
That Example Manager Prints the string you either feed it in options, or the config.
For more details on the ShortCut System, go here:
For more details on the Command System, go here:
For more details on the Config System, Read About Managers or go here:
Updated less than a minute ago