From 17e088392836ae306d27d9c5000815e8252a925d Mon Sep 17 00:00:00 2001 From: Trivernis Date: Sun, 23 Dec 2018 19:30:49 +0100 Subject: [PATCH] Updated jsdoc --- lib/cmd.js | 1 + lib/data.js | 35 ++++++++++++++++++++++++++++++++++- lib/guilding.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/lib/cmd.js b/lib/cmd.js index b5e1d41..a67e488 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -15,6 +15,7 @@ exports.Servant = class { this.createCommand(((prefix || '~')+'help') || "~help", () => { let helpstr = "```markdown\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]) => { let cmdhelp = `${key} [${value.args.join('] [')}]`.replace('[]', '').padEnd(25, ' '); cmdhelp += value.description || ''; diff --git a/lib/data.js b/lib/data.js index 7042bfc..dd59fe1 100644 --- a/lib/data.js +++ b/lib/data.js @@ -41,23 +41,47 @@ exports.DataHandler = class { } } + /** + * adds an entry to the fileEntries. refreshes the entrie file + * @param name + * @param path + */ addEntry(name, path) { this.fileEntries.name = path; this.refreshEntries(); } + /** + * shortcut function to join the path with the working directory + * @param file + * @returns {Promise | string} + */ getfp(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) { fs.readFile(this.getfp, 'utf-8', callback); } + /** + * returns the JSON content of a file in the working directory + * @param file + * @returns {any} + */ getJSONSync(file) { return JSON.parse(fs.readFileSync(this.getfp(file), 'utf-8')); } + /** + * writes all entris of the fileEntries variable into the fileEntries file. + */ refreshEntries() { fs.writeFile(this.getfp(entryfile), JSON.stringify(this.fileEntries), (err) => { if (err) @@ -65,6 +89,11 @@ exports.DataHandler = class { }); } + /** + * returns the data for the entry + * @param name + * @returns {*} + */ getData(name) { try { if (this.fileData[name]) @@ -79,7 +108,11 @@ exports.DataHandler = class { } } - + /** + * sets the entry to data + * @param name + * @param data + */ setData(name, data) { this.fileData[name] = data; if (!this.fileEntries[name]) { diff --git a/lib/guilding.js b/lib/guilding.js index 0c25270..d833845 100644 --- a/lib/guilding.js +++ b/lib/guilding.js @@ -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);