From 5b3322ebba246c3d3581e3e51e3c29671d506a20 Mon Sep 17 00:00:00 2001 From: neelkamath Date: Sat, 12 May 2018 14:49:56 +0530 Subject: Enhance READM.md --- templateCommand.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 templateCommand.js (limited to 'templateCommand.js') diff --git a/templateCommand.js b/templateCommand.js new file mode 100644 index 0000000..1f2cdd9 --- /dev/null +++ b/templateCommand.js @@ -0,0 +1,49 @@ +/* + Description: This is a template module that should not be on prod +*/ + +// you can require() modules here + +// this function will only be only in the scope of the module +const createReply = (echoInput) => { + if (echoInput.length > 100) + echoInput = 'HOW ABOUT NO?'; + + return `You want me to echo: ${echoInput}?` +}; + +/* + `exports.run()` is required and will always be passed (core, server, socket, data) + + be sure it's async too + this is the main function that will run when called +*/ +exports.run = async (core, server, socket, data) => { + + server.reply({ + cmd: 'info', + text: `SHOWCASE MODULE: ${core.showcase} - ${createReply(data.echo)}` + }, socket); + +}; + +/* + `exports.init()` is optional, and will only be run when the module is loaded into memory + it will always be passed a reference to the global core class + note: this will fire again if a reload is issued, keep that in mind +*/ +exports.init = (core) => { + if (typeof core.showcase === 'undefined') { + core.showcase = 'init is a handy place to put global data by assigning it to `core`'; + } +} + +// optional, if `data.echo` is missing `exports.run()` will never be called & the user will be alerted +// remember; this will only verify that the data is not undefined, not the type of data +exports.requiredData = ['echo']; + +// optional parameters are marked, all others are required +exports.info = { + name: 'showcase', // actual command name + aliases: ['templateModule'] +}; -- cgit v1.2.1 From db807bc195cf0dc87f632331040ac47f1f25ea3d Mon Sep 17 00:00:00 2001 From: Neel Kamath Date: Fri, 18 May 2018 11:08:50 +0530 Subject: Attempt 2 --- templateCommand.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'templateCommand.js') diff --git a/templateCommand.js b/templateCommand.js index 1f2cdd9..90b9aa3 100644 --- a/templateCommand.js +++ b/templateCommand.js @@ -43,7 +43,9 @@ exports.init = (core) => { exports.requiredData = ['echo']; // optional parameters are marked, all others are required -exports.info = { +exports.info = { name: 'showcase', // actual command name - aliases: ['templateModule'] -}; + aliases: ['templateModule'], // optional, an array of other names this module can be executed by + usage: 'showcase {echo}', // used for help output, can be ommited if no parameters are required + description: 'Simple command module template & info' // used for help output +}; \ No newline at end of file -- cgit v1.2.1