/** * @author Marzavec ( https://github.com/marzavec ) * @summary Removes a mod * @version 1.1.0 * @description Removes target trip from the config as a mod and downgrades the socket type * @module removemod */ import { Info, } from '../utility/_Constants.js'; import { legacyLevelToLabel, } from '../utility/_LegacyFunctions.js'; import { isAdmin, isModerator, levels, getUserDetails, getAppearance, } from '../utility/_UAC.js'; /** * Executes when invoked by a remote client * @param {Object} env - Environment object with references to core, server, socket & payload * @public * @return {void} */ export async function run({ core, server, socket, payload, }) { // increase rate limit chance and ignore if not admin if (!isAdmin(socket.level)) { return server.police.frisk(socket, 20); } // remove trip from config // eslint-disable-next-line no-param-reassign core.appConfig.data.globalMods = core.appConfig.data.globalMods.filter( (mod) => mod.trip !== payload.trip, ); const { color, flair } = getAppearance(levels.default); // find targets current connections const targetMod = server.findSockets({ trip: payload.trip }); if (targetMod.length !== 0) { // build update notice with new privileges const updateNotice = { ...getUserDetails(targetMod[0]), ...{ cmd: 'updateUser', uType: legacyLevelToLabel(levels.default), level: levels.default, }, }; for (let i = 0, l = targetMod.length; i < l; i += 1) { // downgrade privileges targetMod[i].uType = legacyLevelToLabel(levels.default); targetMod[i].level = levels.default; targetMod[i].color = color; targetMod[i].flair = flair; // inform ex-mod server.send({ cmd: 'info', text: 'You are now a user.', id: Info.Admin.YOU_ARE_USER, channel: targetMod[i].channel, // @todo Multichannel }, targetMod[i]); // notify channel server.broadcast({ ...updateNotice, ...{ channel: targetMod[i].channel, }, }, { channel: targetMod[i].channel }); } } // return success message server.reply({ cmd: 'info', text: `Removed mod trip: ${ payload.trip }, remember to run 'saveconfig' to make it permanent`, id: Info.Admin.MOD_REMOVED, channel: socket.channel, // @todo Multichannel }, socket); // notify all mods server.broadcast({ cmd: 'info', text: `Removed mod: ${payload.trip}`, id: Info.Admin.MOD_REMOVED_BROADCAST, channel: false, // @todo Multichannel, false for global }, { level: isModerator }); return true; } /** * The following payload properties are required to invoke this module: * "trip" * @public * @typedef {Array} removemod/requiredData */ export const requiredData = ['trip']; /** * Module meta information * @public * @typedef {Object} removemod/info * @property {string} name - Module command name * @property {string} category - Module category name * @property {string} description - Information about module * @property {string} usage - Information about module usage */ export const info = { name: 'removemod', category: 'admin', description: 'Removes target trip from the config as a mod and downgrades the socket type', usage: ` API: { cmd: 'removemod', trip: '' }`, };