aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/admin/listusers.js
blob: a539a3cb9576aa01408604e07c682f6169f3bc7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
  Description: Outputs all current channels and their user nicks
*/

exports.run = async (core, server, socket, data) => {
  if (socket.uType != 'admin') {
    // ignore if not admin
    return;
  }

  let channels = {};
  for (var client of server.clients) {
    if (client.channel) {
      if (!channels[client.channel]) {
        channels[client.channel] = [];
      }
      channels[client.channel].push(client.nick);
    }
  }

  let lines = [];
  for (let channel in channels) {
    lines.push(`?${channel} ${channels[channel].join(", ")}`);
  }

  let text = '';
  text += lines.join("\n");

  server.reply({
    cmd: 'info',
    text: text
  }, socket);
};

exports.info = {
  name: 'listusers',
  description: 'Outputs all current channels and sockets in those channels'
};