2022-06-23 00:32:51 +08:00
|
|
|
/**
|
|
|
|
* @author Marzavec ( https://github.com/marzavec )
|
|
|
|
* @summary Create a new mod trip
|
|
|
|
* @version 1.0.0
|
|
|
|
* @description Adds target trip to the config as a mod and upgrades the socket type
|
|
|
|
* @module addmod
|
|
|
|
*/
|
2018-03-10 15:47:00 +08:00
|
|
|
|
2020-11-07 05:16:43 +08:00
|
|
|
import {
|
|
|
|
isAdmin,
|
|
|
|
isModerator,
|
|
|
|
levels,
|
|
|
|
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-06-04 15:07:24 +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-03-10 15:47:00 +08:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// add new trip to config
|
2022-06-23 00:32:51 +08:00
|
|
|
core.appConfig.data.globalMods.push({ trip: payload.trip });
|
2018-03-10 15:47:00 +08:00
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// find targets current connections
|
2020-09-17 13:44:32 +08:00
|
|
|
const newMod = server.findSockets({ trip: payload.trip });
|
2018-03-14 13:26:53 +08:00
|
|
|
if (newMod.length !== 0) {
|
2020-11-07 05:16:43 +08:00
|
|
|
// build update notice with new privileges
|
|
|
|
const updateNotice = {
|
|
|
|
...getUserDetails(newMod[0]),
|
|
|
|
...{
|
|
|
|
cmd: 'updateUser',
|
|
|
|
uType: 'mod', // @todo use legacyLevelToLabel from _LegacyFunctions.js
|
|
|
|
level: levels.moderator,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
for (let i = 0, l = newMod.length; i < l; i += 1) {
|
2022-06-23 00:32:51 +08:00
|
|
|
// upgrade privileges
|
2020-11-07 05:16:43 +08:00
|
|
|
newMod[i].uType = 'mod'; // @todo use legacyLevelToLabel from _LegacyFunctions.js
|
|
|
|
newMod[i].level = levels.moderator;
|
2018-03-10 15:47:00 +08:00
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// inform new mod
|
2018-03-14 13:26:53 +08:00
|
|
|
server.send({
|
2018-03-10 15:47:00 +08:00
|
|
|
cmd: 'info',
|
2019-11-07 15:35:23 +08:00
|
|
|
text: 'You are now a mod.',
|
2020-10-10 13:34:59 +08:00
|
|
|
channel: newMod[i].channel, // @todo Multichannel
|
2018-03-14 13:26:53 +08:00
|
|
|
}, newMod[i]);
|
2020-11-07 05:16:43 +08:00
|
|
|
|
|
|
|
// notify channel
|
|
|
|
server.broadcast({
|
|
|
|
...updateNotice,
|
|
|
|
...{
|
|
|
|
channel: newMod[i].channel,
|
|
|
|
},
|
|
|
|
}, { channel: newMod[i].channel });
|
2018-03-10 15:47:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// return success message
|
2018-03-10 15:47:00 +08:00
|
|
|
server.reply({
|
|
|
|
cmd: 'info',
|
2020-09-17 13:44:32 +08:00
|
|
|
text: `Added mod trip: ${payload.trip}, remember to run 'saveconfig' to make it permanent`,
|
2020-10-10 13:34:59 +08:00
|
|
|
channel: socket.channel, // @todo Multichannel
|
2018-03-10 15:47:00 +08:00
|
|
|
}, socket);
|
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// notify all mods
|
2018-03-10 15:47:00 +08:00
|
|
|
server.broadcast({
|
|
|
|
cmd: 'info',
|
2020-09-17 13:44:32 +08:00
|
|
|
text: `Added mod: ${payload.trip}`,
|
2020-10-10 13:34:59 +08:00
|
|
|
channel: false, // @todo Multichannel, false for global info
|
2020-11-07 05:16:43 +08:00
|
|
|
}, { level: isModerator });
|
2018-03-10 15:47:00 +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} addmod/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} addmod/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-05-13 18:33:22 +08:00
|
|
|
name: 'addmod',
|
2022-06-23 00:32:51 +08:00
|
|
|
category: 'admin',
|
2018-09-30 14:44:36 +08:00
|
|
|
description: 'Adds target trip to the config as a mod and upgrades the socket type',
|
|
|
|
usage: `
|
2019-11-07 15:35:23 +08:00
|
|
|
API: { cmd: 'addmod', trip: '<target trip>' }`,
|
2018-05-13 18:33:22 +08:00
|
|
|
};
|