aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core/morestats.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/commands/core/morestats.js')
-rw-r--r--server/src/commands/core/morestats.js42
1 files changed, 21 insertions, 21 deletions
diff --git a/server/src/commands/core/morestats.js b/server/src/commands/core/morestats.js
index a71729c..3cbf8f3 100644
--- a/server/src/commands/core/morestats.js
+++ b/server/src/commands/core/morestats.js
@@ -3,37 +3,38 @@
*/
// module support functions
-const stripIndents = require('common-tags').stripIndents;
+const { stripIndents } = require('common-tags');
const formatTime = (time) => {
let seconds = time[0] + time[1] / 1e9;
let minutes = Math.floor(seconds / 60);
- seconds = seconds % 60;
+ seconds %= 60;
let hours = Math.floor(minutes / 60);
- minutes = minutes % 60;
+ minutes %= 60;
- let days = Math.floor(hours / 24);
- hours = hours % 24;
+ const days = Math.floor(hours / 24);
+ hours %= 24;
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) => {
+export async function run(core, server, socket) {
// gather connection and channel count
let ips = {};
let channels = {};
- for (let client of server.clients) {
+ // for (const client of server.clients) {
+ this.clients.forEach((client) => {
if (client.channel) {
channels[client.channel] = true;
- ips[client.remoteAddress] = true;
+ ips[client.address] = true;
}
- }
+ });
- let uniqueClientCount = Object.keys(ips).length;
- let uniqueChannels = Object.keys(channels).length;
+ const uniqueClientCount = Object.keys(ips).length;
+ const uniqueChannels = Object.keys(channels).length;
ips = null;
channels = null;
@@ -49,40 +50,39 @@ exports.run = async (core, server, socket, data) => {
users-banned: ${(core.stats.get('users-banned') || 0)}
users-kicked: ${(core.stats.get('users-kicked') || 0)}
stats-requested: ${(core.stats.get('stats-requested') || 0)}
- server-uptime: ${formatTime(process.hrtime(core.stats.get('start-time')))}`
+ server-uptime: ${formatTime(process.hrtime(core.stats.get('start-time')))}`,
}, socket);
// stats are fun
core.stats.increment('stats-requested');
-};
+}
// module hook functions
-exports.initHooks = (server) => {
+export function initHooks(server) {
server.registerHook('in', 'chat', this.statsCheck, 26);
-};
+}
// hooks chat commands checking for /stats
-exports.statsCheck = (core, server, socket, payload) => {
+export function statsCheck(core, server, socket, payload) {
if (typeof payload.text !== 'string') {
return false;
}
if (payload.text.startsWith('/stats')) {
this.run(core, server, socket, {
- cmd: 'morestats'
+ cmd: 'morestats',
});
return false;
}
return payload;
-};
+}
-// module meta
-exports.info = {
+export const info = {
name: 'morestats',
description: 'Sends back current server stats to the calling client',
usage: `
API: { cmd: 'morestats' }
- Text: /stats`
+ Text: /stats`,
};