2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* @author Marzavec ( https://github.com/marzavec )
|
|
|
|
* @summary Removes a mod
|
|
|
|
* @version 1.0.0
|
|
|
|
* @description Removes target trip from the config as a mod and downgrades the socket type
|
|
|
|
* @module removemod
|
|
|
|
*/
|
2018-09-30 14:44:36 +08:00
|
|
|
|
2020-11-07 05:16:43 +08:00
|
|
|
import {
|
|
|
|
isAdmin,
|
|
|
|
isModerator,
|
|
|
|
levels,
|
2020-11-10 03:55:54 +08:00
|
|
|
getUserDetails,
|
2022-06-23 00:32:51 +08:00
|
|
|
} from '../utility/_UAC.js';
|
2020-03-06 00:49:25 +08:00
|
|
|
|
2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* Executes when invoked by a remote client
|
|
|
|
* @param {Object} env - Enviroment object with references to core, server, socket & payload
|
|
|
|
* @public
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2020-09-17 13:44:32 +08:00
|
|
|
export async function run({
|
|
|
|
core, server, socket, payload,
|
|
|
|
}) {
|
2018-09-30 14:44:36 +08:00
|
|
|
// increase rate limit chance and ignore if not admin
|
2020-11-07 05:16:43 +08:00
|
|
|
if (!isAdmin(socket.level)) {
|
2023-12-27 16:26:49 +08:00
|
|
|
return server.police.frisk(socket, 20);
|
2018-09-30 14:44:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove trip from config
|
2020-09-17 13:44:32 +08:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
2022-06-23 00:32:51 +08:00
|
|
|
core.appConfig.data.globalMods = core.appConfig.data.globalMods.filter(
|
|
|
|
(mod) => mod.trip !== payload.trip,
|
|
|
|
);
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
// find targets current connections
|
2020-09-17 13:44:32 +08:00
|
|
|
const targetMod = server.findSockets({ trip: payload.trip });
|
2019-02-03 05:34:06 +08:00
|
|
|
if (targetMod.length !== 0) {
|
2020-11-10 03:55:54 +08:00
|
|
|
// build update notice with new privileges
|
|
|
|
const updateNotice = {
|
|
|
|
...getUserDetails(targetMod[0]),
|
|
|
|
...{
|
|
|
|
cmd: 'updateUser',
|
|
|
|
uType: 'user', // @todo use legacyLevelToLabel from _LegacyFunctions.js
|
|
|
|
level: levels.default,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
for (let i = 0, l = targetMod.length; i < l; i += 1) {
|
2022-06-23 00:32:51 +08:00
|
|
|
// downgrade privileges
|
2023-12-22 15:14:03 +08:00
|
|
|
targetMod[i].uType = 'user';
|
2020-11-07 05:16:43 +08:00
|
|
|
targetMod[i].level = levels.default;
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
// inform ex-mod
|
|
|
|
server.send({
|
|
|
|
cmd: 'info',
|
2019-11-07 15:35:23 +08:00
|
|
|
text: 'You are now a user.',
|
2020-10-10 13:34:59 +08:00
|
|
|
channel: targetMod[i].channel, // @todo Multichannel
|
2018-09-30 14:44:36 +08:00
|
|
|
}, targetMod[i]);
|
2020-11-10 03:55:54 +08:00
|
|
|
|
|
|
|
// notify channel
|
|
|
|
server.broadcast({
|
|
|
|
...updateNotice,
|
|
|
|
...{
|
|
|
|
channel: targetMod[i].channel,
|
|
|
|
},
|
|
|
|
}, { channel: targetMod[i].channel });
|
2018-09-30 14:44:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return success message
|
|
|
|
server.reply({
|
|
|
|
cmd: 'info',
|
2019-02-03 05:34:06 +08:00
|
|
|
text: `Removed mod trip: ${
|
2020-09-17 13:44:32 +08:00
|
|
|
payload.trip
|
2019-11-07 15:35:23 +08:00
|
|
|
}, remember to run 'saveconfig' to make it permanent`,
|
2020-10-10 13:34:59 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
2018-09-30 14:44:36 +08:00
|
|
|
}, socket);
|
|
|
|
|
|
|
|
// notify all mods
|
|
|
|
server.broadcast({
|
|
|
|
cmd: 'info',
|
2020-09-17 13:44:32 +08:00
|
|
|
text: `Removed mod: ${payload.trip}`,
|
2020-10-10 13:34:59 +08:00
|
|
|
channel: false, // @todo Multichannel, false for global
|
2020-11-07 05:16:43 +08:00
|
|
|
}, { level: isModerator });
|
2018-09-30 14:44:36 +08:00
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* The following payload properties are required to invoke this module:
|
|
|
|
* "trip"
|
|
|
|
* @public
|
|
|
|
* @typedef {Array} removemod/requiredData
|
|
|
|
*/
|
2019-11-07 15:35:23 +08:00
|
|
|
export const requiredData = ['trip'];
|
2022-06-23 00:32:51 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2019-11-07 15:35:23 +08:00
|
|
|
export const info = {
|
2018-09-30 14:44:36 +08:00
|
|
|
name: 'removemod',
|
2022-06-23 00:32:51 +08:00
|
|
|
category: 'admin',
|
2018-09-30 14:44:36 +08:00
|
|
|
description: 'Removes target trip from the config as a mod and downgrades the socket type',
|
|
|
|
usage: `
|
2019-11-07 15:35:23 +08:00
|
|
|
API: { cmd: 'removemod', trip: '<target trip>' }`,
|
2018-09-30 14:44:36 +08:00
|
|
|
};
|