1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00
hack-chat-main/server/src/commands/admin/removemod.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

/*
Description: Removes target trip from the config as a mod and downgrades the socket type
*/
// module main
2019-11-07 15:35:23 +08:00
export async function run(core, server, socket, data) {
// increase rate limit chance and ignore if not admin
2019-11-07 15:35:23 +08:00
if (socket.uType !== 'admin') {
return server.police.frisk(socket.address, 20);
}
// remove trip from config
2019-11-07 15:35:23 +08:00
core.config.mods = core.config.mods.filter((mod) => mod.trip !== data.trip);
// find targets current connections
2019-11-07 15:35:23 +08:00
const targetMod = server.findSockets({ trip: data.trip });
if (targetMod.length !== 0) {
2019-11-07 15:35:23 +08:00
for (let i = 0, l = targetMod.length; i < l; i += 1) {
// downgrade privilages
targetMod[i].uType = 'user';
// inform ex-mod
server.send({
cmd: 'info',
2019-11-07 15:35:23 +08:00
text: 'You are now a user.',
}, targetMod[i]);
}
}
// return success message
server.reply({
cmd: 'info',
text: `Removed mod trip: ${
data.trip
2019-11-07 15:35:23 +08:00
}, remember to run 'saveconfig' to make it permanent`,
}, socket);
// notify all mods
server.broadcast({
cmd: 'info',
2019-11-07 15:35:23 +08:00
text: `Removed mod: ${data.trip}`,
}, { uType: 'mod' });
2019-11-07 15:35:23 +08:00
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: `
2019-11-07 15:35:23 +08:00
API: { cmd: 'removemod', trip: '<target trip>' }`,
};