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/addmod.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-03-10 15:47:00 +08:00
/*
Description: Adds the target trip to the mod list then elevates the uType
2018-03-10 15:47:00 +08:00
*/
import * as UAC from '../utility/UAC/_info';
// module main
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
if (!UAC.isAdmin(socket.level)) {
2019-11-07 15:35:23 +08:00
return server.police.frisk(socket.address, 20);
2018-03-10 15:47:00 +08:00
}
2018-06-04 15:07:24 +08:00
// add new trip to config
2020-09-17 13:44:32 +08:00
core.config.mods.push({ trip: payload.trip });
2018-03-10 15:47:00 +08:00
// find targets current connections
2020-09-17 13:44:32 +08:00
const newMod = server.findSockets({ trip: payload.trip });
if (newMod.length !== 0) {
2019-11-07 15:35:23 +08:00
for (let i = 0, l = newMod.length; i < l; i += 1) {
// upgrade privilages
newMod[i].uType = 'mod';
newMod[i].level = UAC.levels.moderator;
2018-03-10 15:47:00 +08:00
// inform new mod
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.',
}, newMod[i]);
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`,
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}`,
}, { level: UAC.isModerator });
2018-03-10 15:47:00 +08:00
2019-11-07 15:35:23 +08:00
return true;
}
export const requiredData = ['trip'];
export const info = {
2018-05-13 18:33:22 +08:00
name: 'addmod',
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
};