Updated jsdoc

pull/11/head
Trivernis 6 years ago
parent 63981f2a90
commit 17e0883928

@ -15,6 +15,7 @@ exports.Servant = class {
this.createCommand(((prefix || '~')+'help') || "~help", () => { this.createCommand(((prefix || '~')+'help') || "~help", () => {
let helpstr = "```markdown\n"; let helpstr = "```markdown\n";
helpstr += "Commands\n---\n"; helpstr += "Commands\n---\n";
// TODO: Duplicate commands should not appear or make two sections, one with global commands, one with server commands
Object.entries(globCommands).concat(Object.entries(this.commands)).forEach(([key, value]) => { Object.entries(globCommands).concat(Object.entries(this.commands)).forEach(([key, value]) => {
let cmdhelp = `${key} [${value.args.join('] [')}]`.replace('[]', '').padEnd(25, ' '); let cmdhelp = `${key} [${value.args.join('] [')}]`.replace('[]', '').padEnd(25, ' ');
cmdhelp += value.description || ''; cmdhelp += value.description || '';

@ -41,23 +41,47 @@ exports.DataHandler = class {
} }
} }
/**
* adds an entry to the fileEntries. refreshes the entrie file
* @param name
* @param path
*/
addEntry(name, path) { addEntry(name, path) {
this.fileEntries.name = path; this.fileEntries.name = path;
this.refreshEntries(); this.refreshEntries();
} }
/**
* shortcut function to join the path with the working directory
* @param file
* @returns {Promise<VoiceConnection> | string}
*/
getfp(file) { getfp(file) {
return path.join(this.workingDir, file); return path.join(this.workingDir, file);
} }
/**
* shortcut function that evokes the callback after reading the file. the files path is the name
* joined with the working directory
* @param file
* @param callback
*/
getcont(file, callback) { getcont(file, callback) {
fs.readFile(this.getfp, 'utf-8', callback); fs.readFile(this.getfp, 'utf-8', callback);
} }
/**
* returns the JSON content of a file in the working directory
* @param file
* @returns {any}
*/
getJSONSync(file) { getJSONSync(file) {
return JSON.parse(fs.readFileSync(this.getfp(file), 'utf-8')); return JSON.parse(fs.readFileSync(this.getfp(file), 'utf-8'));
} }
/**
* writes all entris of the fileEntries variable into the fileEntries file.
*/
refreshEntries() { refreshEntries() {
fs.writeFile(this.getfp(entryfile), JSON.stringify(this.fileEntries), (err) => { fs.writeFile(this.getfp(entryfile), JSON.stringify(this.fileEntries), (err) => {
if (err) if (err)
@ -65,6 +89,11 @@ exports.DataHandler = class {
}); });
} }
/**
* returns the data for the entry <name>
* @param name
* @returns {*}
*/
getData(name) { getData(name) {
try { try {
if (this.fileData[name]) if (this.fileData[name])
@ -79,7 +108,11 @@ exports.DataHandler = class {
} }
} }
/**
* sets the entry <name> to data
* @param name
* @param data
*/
setData(name, data) { setData(name, data) {
this.fileData[name] = data; this.fileData[name] = data;
if (!this.fileEntries[name]) { if (!this.fileEntries[name]) {

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

Loading…
Cancel
Save