|
|
|
@ -9,6 +9,7 @@ exports.setLogger = function (newLogger) {
|
|
|
|
|
music.setLogger(logger);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.GuildHandler = class {
|
|
|
|
|
constructor(guild, prefix) {
|
|
|
|
|
this.guild = guild;
|
|
|
|
@ -20,22 +21,42 @@ exports.GuildHandler = class {
|
|
|
|
|
this.registerMusicCommands();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* function shortcut returns the data from the dataHandler
|
|
|
|
|
* @param name
|
|
|
|
|
* @returns {{}}
|
|
|
|
|
*/
|
|
|
|
|
getData(name) {
|
|
|
|
|
return this.dataHandler.getData(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* appends data to the data handler
|
|
|
|
|
* @param name
|
|
|
|
|
* @param key
|
|
|
|
|
* @param value
|
|
|
|
|
*/
|
|
|
|
|
appendData(name, key, value) {
|
|
|
|
|
let data = this.getData(name);
|
|
|
|
|
data[key] = value;
|
|
|
|
|
this.dataHandler.setData(name, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* deletes an entry from the data handler
|
|
|
|
|
* @param name
|
|
|
|
|
* @param key
|
|
|
|
|
*/
|
|
|
|
|
deleteDataEntry(name, key) {
|
|
|
|
|
let data = this.getData(name);
|
|
|
|
|
delete data[key];
|
|
|
|
|
this.dataHandler.setData(name, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* registers all music commands and initializes a dj
|
|
|
|
|
* @param cmdPrefix
|
|
|
|
|
*/
|
|
|
|
|
registerMusicCommands(cmdPrefix) {
|
|
|
|
|
let prefix = cmdPrefix || this.prefix;
|
|
|
|
|
this.dj = new music.DJ();
|
|
|
|
@ -170,11 +191,23 @@ exports.GuildHandler = class {
|
|
|
|
|
}, [], "Prints out all saved playlists.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* creates a servant if not set and lets the servant create a command
|
|
|
|
|
* @param command
|
|
|
|
|
* @param call
|
|
|
|
|
* @param args
|
|
|
|
|
* @param description
|
|
|
|
|
*/
|
|
|
|
|
createCommand(command, call, args, description) {
|
|
|
|
|
if (!this.servant) this.servant = new cmd.Servant(this.prefix);
|
|
|
|
|
this.servant.createCommand(command, call, args, description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* handles the message by letting the servant parse the command. Depending on the message setting it
|
|
|
|
|
* replies or just sends the answer.
|
|
|
|
|
* @param msg
|
|
|
|
|
*/
|
|
|
|
|
handleMessage(msg) {
|
|
|
|
|
if (!this.servant) this.servant = new cmd.Servant(this.prefix);
|
|
|
|
|
let answer = this.servant.parseCommand(msg);
|
|
|
|
|