diff options
author | marzavec <admin@marzavec.com> | 2018-09-30 08:44:36 +0200 |
---|---|---|
committer | marzavec <admin@marzavec.com> | 2018-09-30 08:44:36 +0200 |
commit | c719020e17cb1c98da55be6cc7efe0e50ab51ffa (patch) | |
tree | 4c1e7f05aec2b6a995e21d2bbecbb45c2ae14bd6 /server/src/commands/core/morestats.js | |
parent | Merge pull request #28 from henrywright/27 (diff) | |
download | hackchat-c719020e17cb1c98da55be6cc7efe0e50ab51ffa.tar.gz hackchat-c719020e17cb1c98da55be6cc7efe0e50ab51ffa.zip |
Added hooks, modules and cleaned up code
Diffstat (limited to '')
-rw-r--r-- | server/src/commands/core/morestats.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/server/src/commands/core/morestats.js b/server/src/commands/core/morestats.js index b64d478..e8eed05 100644 --- a/server/src/commands/core/morestats.js +++ b/server/src/commands/core/morestats.js @@ -2,6 +2,7 @@ Description: Outputs more info than the legacy stats command */ +// module support functions const stripIndents = require('common-tags').stripIndents; const formatTime = (time) => { @@ -19,6 +20,7 @@ const formatTime = (time) => { return `${days.toFixed(0)}d ${hours.toFixed(0)}h ${minutes.toFixed(0)}m ${seconds.toFixed(0)}s`; }; +// module main exports.run = async (core, server, socket, data) => { // gather connection and channel count let ips = {}; @@ -54,7 +56,33 @@ exports.run = async (core, server, socket, data) => { core.managers.stats.increment('stats-requested'); }; +// module hook functions +exports.initHooks = (server) => { + server.registerHook('in', 'chat', this.statsCheck); +}; + +// hooks chat commands checking for /stats +exports.statsCheck = (core, server, socket, payload) => { + if (typeof payload.text !== 'string') { + return false; + } + + if (payload.text.startsWith('/stats')) { + this.run(core, server, socket, { + cmd: 'morestats' + }); + + return false; + } + + return payload; +}; + +// module meta exports.info = { name: 'morestats', - description: 'Sends back current server stats to the calling client' + description: 'Sends back current server stats to the calling client', + usage: ` + API: { cmd: 'morestats' } + Text: /stats` }; |