1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00
hack-chat-main/commands/core/stats.js

41 lines
994 B
JavaScript
Raw Normal View History

2018-03-10 15:47:00 +08:00
/*
Description: Legacy stats output, kept for compatibility, outputs user and channel count
2018-03-10 15:47:00 +08:00
*/
// module main
2020-09-17 13:44:32 +08:00
export async function run({ core, server, socket }) {
2018-06-04 15:07:24 +08:00
// gather connection and channel count
2018-03-10 15:47:00 +08:00
let ips = {};
let channels = {};
2019-11-07 15:35:23 +08:00
// for (const client of server.clients) {
2019-11-08 01:46:55 +08:00
server.clients.forEach((client) => {
2018-03-10 15:47:00 +08:00
if (client.channel) {
channels[client.channel] = true;
2019-11-07 15:35:23 +08:00
ips[client.address] = true;
2018-03-10 15:47:00 +08:00
}
2019-11-07 15:35:23 +08:00
});
2018-03-10 15:47:00 +08:00
2019-11-07 15:35:23 +08:00
const uniqueClientCount = Object.keys(ips).length;
const uniqueChannels = Object.keys(channels).length;
2018-03-10 15:47:00 +08:00
ips = null;
channels = null;
2018-06-04 15:07:24 +08:00
// dispatch info
2018-03-10 15:47:00 +08:00
server.reply({
cmd: 'info',
2019-11-07 15:35:23 +08:00
text: `${uniqueClientCount} unique IPs in ${uniqueChannels} channels`,
2020-10-10 13:34:59 +08:00
channel: socket.channel, // @todo Multichannel
2018-03-10 15:47:00 +08:00
}, socket);
2018-06-04 15:07:24 +08:00
// stats are fun
2019-03-19 14:36:21 +08:00
core.stats.increment('stats-requested');
2019-11-07 15:35:23 +08:00
}
2018-03-10 15:47:00 +08:00
2019-11-07 15:35:23 +08:00
export const info = {
2018-05-13 18:33:22 +08:00
name: 'stats',
description: 'Sends back legacy server stats to the calling client',
usage: `
2019-11-07 15:35:23 +08:00
API: { cmd: 'stats' }`,
2018-06-04 15:07:24 +08:00
};