From 4a2f0d6f59a281706ba6a1d370cf9be403cc1ee1 Mon Sep 17 00:00:00 2001 From: marzavec Date: Sat, 13 Oct 2018 16:35:58 -0700 Subject: [PATCH] documentation update, removing unused scripts --- documentation/templateCommand.js | 72 +++++++++++++++++++++++++------- server/src/scripts/debug.js | 18 -------- server/src/scripts/dev.js | 17 -------- 3 files changed, 57 insertions(+), 50 deletions(-) delete mode 100644 server/src/scripts/debug.js delete mode 100644 server/src/scripts/dev.js diff --git a/documentation/templateCommand.js b/documentation/templateCommand.js index 1a4f3d2..c9f3604 100644 --- a/documentation/templateCommand.js +++ b/documentation/templateCommand.js @@ -6,6 +6,7 @@ // you can require() modules here // this function will only be only in the scope of the module +// module support functions const createReply = (echoInput) => { if (echoInput.length > 100) echoInput = 'HOW ABOUT NO?'; @@ -13,21 +14,6 @@ const createReply = (echoInput) => { 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 @@ -39,6 +25,62 @@ exports.init = (core) => { } } +/* + `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 +*/ +// module main +exports.run = async (core, server, socket, data) => { + + server.reply({ + cmd: 'info', + text: `SHOWCASE MODULE: ${core.showcase} - ${createReply(data.echo)}` + }, socket); + +}; + +/* + `exports.initHooks` is optional, this will be called when the server is ready + for modules to register their hooking functions + + Hook function may alter the data before it is sent to a module, or before it + is sent to a client. If the function returns `false` then the data will be + dropped without further processing +*/ +// module hook functions +exports.initHooks = (server) => { + /* + First param is hook type. A hook may be registered as either `in` or `out`: + `in`: a hook function registered as `in` will be called before the client + request is passed to the module they are attempting to call. Note: socket + in this context is the client that sent the data + `out`: a hook function registerd as `out` will be called before the data is + sent to any clients. Note: `socket` in this context is the socket that + will be sent the data. + + Second param is the `cmd` type to target, any valid module may be targeted + + Third param is the hook function itself, see `exports.hookExample` for an example + */ + server.registerHook('in', 'chat', this.hookExample); +}; + +/* + This hook function example alters the payload before it gets to the `chat` module, + changing the user's input from 'hookexample' to 'WORKING!' +*/ +exports.hookExample = (core, server, socket, payload) => { + // check if we need to alter the payload + if (payload.text === 'hookexample') { + payload.text = 'WORKING!'; + } + + // always return the payload, or false if processing should drop it + return payload; +} + // 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']; diff --git a/server/src/scripts/debug.js b/server/src/scripts/debug.js deleted file mode 100644 index 3a97d9f..0000000 --- a/server/src/scripts/debug.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Server debug test script - * - * Version: v2.0.0 - * Developer: Marzavec ( https://github.com/marzavec ) - * License: WTFPL ( http://www.wtfpl.net/txt/copying/ ) - * - */ - -'use strict'; - -// import required classes -const path = require('path'); -const ConfigManager = require('../managers/config'); - -// begin tests -// TODO: TODO -// TODO diff --git a/server/src/scripts/dev.js b/server/src/scripts/dev.js deleted file mode 100644 index 5049b84..0000000 --- a/server/src/scripts/dev.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Server development script - * - * Version: v2.0.0 - * Developer: Marzavec ( https://github.com/marzavec ) - * License: WTFPL ( http://www.wtfpl.net/txt/copying/ ) - * - */ - -'use strict'; - -// import required classes - - -// begin tests -// TODO: TODO -// TODO