diff options
author | Neel Kamath <neelkamath@protonmail.com> | 2018-05-13 12:39:55 +0200 |
---|---|---|
committer | Neel Kamath <neelkamath@protonmail.com> | 2018-05-13 12:39:55 +0200 |
commit | 2bb5ced363b692a5696b176bc317fe525c0c05df (patch) | |
tree | 1532d9456c5f2b25ac05f7cec620a3af890eff83 /server/commands/admin | |
parent | Re-add module documentation (diff) | |
download | hackchat-2bb5ced363b692a5696b176bc317fe525c0c05df.tar.gz hackchat-2bb5ced363b692a5696b176bc317fe525c0c05df.zip |
Flatten
Diffstat (limited to 'server/commands/admin')
-rw-r--r-- | server/commands/admin/addmod.js | 47 | ||||
-rw-r--r-- | server/commands/admin/listusers.js | 38 | ||||
-rw-r--r-- | server/commands/admin/reload.js | 35 | ||||
-rw-r--r-- | server/commands/admin/saveconfig.js | 36 | ||||
-rw-r--r-- | server/commands/admin/shout.js | 23 |
5 files changed, 179 insertions, 0 deletions
diff --git a/server/commands/admin/addmod.js b/server/commands/admin/addmod.js new file mode 100644 index 0000000..4c13b22 --- /dev/null +++ b/server/commands/admin/addmod.js @@ -0,0 +1,47 @@ +/* + Description: Adds the target trip to the mod list then elevates the uType +*/ + +exports.run = async (core, server, socket, data) => { + if (socket.uType != 'admin') { + // ignore if not admin + return; + } + + let mod = { + trip: data.trip + } + + core.config.mods.push(mod); // purposely not using `config.set()` to avoid auto-save + + let newMod = server.findSockets({ trip: data.trip }); + + if (newMod.length !== 0) { + for (let i = 0, l = newMod.length; i < l; i++) { + newMod[i].uType = 'mod'; + + server.send({ + cmd: 'info', + text: 'You are now a mod.' + }, newMod[i]); + } + } + + server.reply({ + cmd: 'info', + text: `Added mod trip: ${data.trip}` + }, socket); + + server.broadcast({ + cmd: 'info', + text: `Added mod trip: ${data.trip}` + }, { uType: 'mod' }); +}; + +exports.requiredData = ['trip']; + +exports.info = { + name: 'addmod', + usage: 'addmod {trip}', + description: 'Adds target trip to the config as a mod and upgrades the socket type' +}; diff --git a/server/commands/admin/listusers.js b/server/commands/admin/listusers.js new file mode 100644 index 0000000..a539a3c --- /dev/null +++ b/server/commands/admin/listusers.js @@ -0,0 +1,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' +}; diff --git a/server/commands/admin/reload.js b/server/commands/admin/reload.js new file mode 100644 index 0000000..e2cfbe6 --- /dev/null +++ b/server/commands/admin/reload.js @@ -0,0 +1,35 @@ +/* + Description: Clears and resets the command modules, outputting any errors +*/ + +exports.run = async (core, server, socket, data) => { + if (socket.uType != 'admin') { + // ignore if not admin + return; + } + + let loadResult = core.managers.dynamicImports.reloadDirCache('src/commands'); + loadResult += core.commands.loadCommands(); + + if (loadResult == '') { + loadResult = `Loaded ${core.commands._commands.length} commands, 0 errors`; + } else { + loadResult = `Loaded ${core.commands._commands.length} commands, error(s): ${loadResult}`; + } + + server.reply({ + cmd: 'info', + text: loadResult + }, socket); + + server.broadcast({ + cmd: 'info', + text: loadResult + }, { uType: 'mod' }); +}; + +exports.info = { + name: 'reload', + description: '(Re)loads any new commands into memory, outputs errors if any' +}; + diff --git a/server/commands/admin/saveconfig.js b/server/commands/admin/saveconfig.js new file mode 100644 index 0000000..ed3a312 --- /dev/null +++ b/server/commands/admin/saveconfig.js @@ -0,0 +1,36 @@ +/* + Description: Writes any changes to the config to the disk +*/ + +exports.run = async (core, server, socket, data) => { + if (socket.uType != 'admin') { + // ignore if not admin + return; + } + + let saveResult = core.managers.config.save(); + + if (!saveResult) { + server.reply({ + cmd: 'warn', + text: 'Failed to save config, check logs.' + }, client); + + return; + } + + server.reply({ + cmd: 'info', + text: 'Config saved!' + }, socket); + + server.broadcast({ + cmd: 'info', + text: 'Config saved!' + }, { uType: 'mod' }); +}; + +exports.info = { + name: 'saveconfig', + description: 'Saves current config' +}; diff --git a/server/commands/admin/shout.js b/server/commands/admin/shout.js new file mode 100644 index 0000000..1358dd9 --- /dev/null +++ b/server/commands/admin/shout.js @@ -0,0 +1,23 @@ +/* + Description: Emmits a server-wide message as `info` +*/ + +exports.run = async (core, server, socket, data) => { + if (socket.uType != 'admin') { + // ignore if not admin + return; + } + + server.broadcast( { + cmd: 'info', + text: `Server Notice: ${data.text}` + }, {}); +}; + +exports.requiredData = ['text']; + +exports.info = { + name: 'shout', + usage: 'shout {text}', + description: 'Displays passed text to every client connected' +};
\ No newline at end of file |