diff options
author | marzavec <admin@marzavec.com> | 2019-11-07 08:35:23 +0100 |
---|---|---|
committer | marzavec <admin@marzavec.com> | 2019-11-07 08:35:23 +0100 |
commit | f28e65ab8035682372edbe1c11d9ca2581e0a2e6 (patch) | |
tree | a75c9b682ca245baa3f01df5ea704ba95205cef3 /server/src/commands/admin | |
parent | Merge pull request #79 from 0x17de/feature-emote-trip (diff) | |
download | hackchat-f28e65ab8035682372edbe1c11d9ca2581e0a2e6.tar.gz hackchat-f28e65ab8035682372edbe1c11d9ca2581e0a2e6.zip |
Syntax update and formatting tweaks
Diffstat (limited to 'server/src/commands/admin')
-rw-r--r-- | server/src/commands/admin/addmod.js | 27 | ||||
-rw-r--r-- | server/src/commands/admin/listusers.js | 35 | ||||
-rw-r--r-- | server/src/commands/admin/reload.js | 21 | ||||
-rw-r--r-- | server/src/commands/admin/removemod.js | 29 | ||||
-rw-r--r-- | server/src/commands/admin/saveconfig.js | 23 | ||||
-rw-r--r-- | server/src/commands/admin/shout.js | 19 |
6 files changed, 80 insertions, 74 deletions
diff --git a/server/src/commands/admin/addmod.js b/server/src/commands/admin/addmod.js index 6853a42..26cec40 100644 --- a/server/src/commands/admin/addmod.js +++ b/server/src/commands/admin/addmod.js @@ -3,26 +3,26 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin - if (socket.uType != 'admin') { - return server.police.frisk(socket.remoteAddress, 20); + if (socket.uType !== 'admin') { + return server.police.frisk(socket.address, 20); } // add new trip to config core.config.mods.push({ trip: data.trip }); // find targets current connections - let newMod = server.findSockets({ trip: data.trip }); + const newMod = server.findSockets({ trip: data.trip }); if (newMod.length !== 0) { - for (let i = 0, l = newMod.length; i < l; i++) { + for (let i = 0, l = newMod.length; i < l; i += 1) { // upgrade privilages newMod[i].uType = 'mod'; // inform new mod server.send({ cmd: 'info', - text: 'You are now a mod.' + text: 'You are now a mod.', }, newMod[i]); } } @@ -30,21 +30,22 @@ exports.run = async (core, server, socket, data) => { // return success message server.reply({ cmd: 'info', - text: `Added mod trip: ${data.trip}, remember to run 'saveconfig' to make it permanent` + text: `Added mod trip: ${data.trip}, remember to run 'saveconfig' to make it permanent`, }, socket); // notify all mods server.broadcast({ cmd: 'info', - text: `Added mod: ${data.trip}` + text: `Added mod: ${data.trip}`, }, { uType: 'mod' }); -}; -// module meta -exports.requiredData = ['trip']; -exports.info = { + return true; +} + +export const requiredData = ['trip']; +export const info = { name: 'addmod', description: 'Adds target trip to the config as a mod and upgrades the socket type', usage: ` - API: { cmd: 'addmod', trip: '<target trip>' }` + API: { cmd: 'addmod', trip: '<target trip>' }`, }; diff --git a/server/src/commands/admin/listusers.js b/server/src/commands/admin/listusers.js index 5ff350f..0b0199f 100644 --- a/server/src/commands/admin/listusers.js +++ b/server/src/commands/admin/listusers.js @@ -3,46 +3,47 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket) { // increase rate limit chance and ignore if not admin - if (socket.uType != 'admin') { - return server.police.frisk(socket.remoteAddress, 20); + if (socket.uType !== 'admin') { + return server.police.frisk(socket.address, 20); } // find all users currently in a channel - let currentUsers = server.findSockets({ - channel: (channel) => true + const currentUsers = server.findSockets({ + channel: (channel) => true, }); // compile channel and user list - let channels = {}; - for (let i = 0, j = currentUsers.length; i < j; i++) { + const channels = {}; + for (let i = 0, j = currentUsers.length; i < j; i += 1) { if (typeof channels[currentUsers[i].channel] === 'undefined') { channels[currentUsers[i].channel] = []; } - + channels[currentUsers[i].channel].push( - `[${currentUsers[i].trip||'null'}]${currentUsers[i].nick}` + `[${currentUsers[i].trip || 'null'}]${currentUsers[i].nick}`, ); } // build output - let lines = []; - for (let channel in channels) { - lines.push(`?${channel} ${channels[channel].join(", ")}`); + const lines = []; + for (const channel in channels) { + lines.push(`?${channel} ${channels[channel].join(', ')}`); } // send reply server.reply({ cmd: 'info', - text: lines.join("\n") + text: lines.join('\n'), }, socket); -}; -// module meta -exports.info = { + return true; +} + +export const info = { name: 'listusers', description: 'Outputs all current channels and sockets in those channels', usage: ` - API: { cmd: 'listusers' }` + API: { cmd: 'listusers' }`, }; diff --git a/server/src/commands/admin/reload.js b/server/src/commands/admin/reload.js index 588d1c5..206e2ca 100644 --- a/server/src/commands/admin/reload.js +++ b/server/src/commands/admin/reload.js @@ -3,10 +3,10 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin - if (socket.uType != 'admin') { - return server.police.frisk(socket.remoteAddress, 20); + if (socket.uType !== 'admin') { + return server.police.frisk(socket.address, 20); } // do command reload and store results @@ -17,7 +17,7 @@ exports.run = async (core, server, socket, data) => { server.loadHooks(); // build reply based on reload results - if (loadResult == '') { + if (loadResult === '') { loadResult = `Reloaded ${core.commands.commands.length} commands, 0 errors`; } else { loadResult = `Reloaded ${core.commands.commands.length} commands, error(s): @@ -31,20 +31,21 @@ exports.run = async (core, server, socket, data) => { // reply with results server.reply({ cmd: 'info', - text: loadResult + text: loadResult, }, socket); // notify mods of reload #transparency server.broadcast({ cmd: 'info', - text: loadResult + text: loadResult, }, { uType: 'mod' }); -}; -// module meta -exports.info = { + return true; +} + +export const info = { name: 'reload', description: '(Re)loads any new commands into memory, outputs errors if any', usage: ` - API: { cmd: 'reload', reason: '<optional reason append>' }` + API: { cmd: 'reload', reason: '<optional reason append>' }`, }; diff --git a/server/src/commands/admin/removemod.js b/server/src/commands/admin/removemod.js index a2d862c..9190dd6 100644 --- a/server/src/commands/admin/removemod.js +++ b/server/src/commands/admin/removemod.js @@ -3,26 +3,26 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin - if (socket.uType != 'admin') { - return server.police.frisk(socket.remoteAddress, 20); + if (socket.uType !== 'admin') { + return server.police.frisk(socket.address, 20); } // remove trip from config - core.config.mods = core.config.mods.filter(mod => mod.trip !== data.trip); + core.config.mods = core.config.mods.filter((mod) => mod.trip !== data.trip); // find targets current connections - let targetMod = server.findSockets({ trip: data.trip }); + const targetMod = server.findSockets({ trip: data.trip }); if (targetMod.length !== 0) { - for (let i = 0, l = targetMod.length; i < l; i++) { + for (let i = 0, l = targetMod.length; i < l; i += 1) { // downgrade privilages targetMod[i].uType = 'user'; // inform ex-mod server.send({ cmd: 'info', - text: 'You are now a user.' + text: 'You are now a user.', }, targetMod[i]); } } @@ -32,21 +32,22 @@ exports.run = async (core, server, socket, data) => { cmd: 'info', text: `Removed mod trip: ${ data.trip - }, remember to run 'saveconfig' to make it permanent` + }, remember to run 'saveconfig' to make it permanent`, }, socket); // notify all mods server.broadcast({ cmd: 'info', - text: `Removed mod: ${data.trip}` + text: `Removed mod: ${data.trip}`, }, { uType: 'mod' }); -}; -// module meta -exports.requiredData = ['trip']; -exports.info = { + return true; +} + +export const requiredData = ['trip']; +export const info = { name: 'removemod', description: 'Removes target trip from the config as a mod and downgrades the socket type', usage: ` - API: { cmd: 'removemod', trip: '<target trip>' }` + API: { cmd: 'removemod', trip: '<target trip>' }`, }; diff --git a/server/src/commands/admin/saveconfig.js b/server/src/commands/admin/saveconfig.js index 65fff0e..6c713b4 100644 --- a/server/src/commands/admin/saveconfig.js +++ b/server/src/commands/admin/saveconfig.js @@ -3,37 +3,38 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket) { // increase rate limit chance and ignore if not admin - if (socket.uType != 'admin') { - return server.police.frisk(socket.remoteAddress, 20); + if (socket.uType !== 'admin') { + return server.police.frisk(socket.address, 20); } // attempt save, notify of failure if (!core.configManager.save()) { return server.reply({ cmd: 'warn', - text: 'Failed to save config, check logs.' - }, client); + text: 'Failed to save config, check logs.', + }, socket); } // return success message server.reply({ cmd: 'info', - text: 'Config saved!' + text: 'Config saved!', }, socket); // notify mods #transparency server.broadcast({ cmd: 'info', - text: 'Config saved!' + text: 'Config saved!', }, { uType: 'mod' }); -}; -// module meta -exports.info = { + return true; +} + +export const info = { name: 'saveconfig', description: 'Writes the current config to disk', usage: ` - API: { cmd: 'saveconfig' }` + API: { cmd: 'saveconfig' }`, }; diff --git a/server/src/commands/admin/shout.js b/server/src/commands/admin/shout.js index 821a22a..73b0734 100644 --- a/server/src/commands/admin/shout.js +++ b/server/src/commands/admin/shout.js @@ -3,24 +3,25 @@ */ // module main -exports.run = async (core, server, socket, data) => { +export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin - if (socket.uType != 'admin') { - return server.police.frisk(socket.remoteAddress, 20); + if (socket.uType !== 'admin') { + return server.police.frisk(socket.address, 20); } // send text to all channels server.broadcast({ cmd: 'info', - text: `Server Notice: ${data.text}` + text: `Server Notice: ${data.text}`, }, {}); -}; -// module meta -exports.requiredData = ['text']; -exports.info = { + return true; +} + +export const requiredData = ['text']; +export const info = { name: 'shout', description: 'Displays passed text to every client connected', usage: ` - API: { cmd: 'shout', text: '<shout text>' }` + API: { cmd: 'shout', text: '<shout text>' }`, }; |