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

90 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

2023-12-22 15:14:03 +08:00
/* eslint no-console: 0 */
/**
* @author Marzavec ( https://github.com/marzavec )
* @summary Unlock target channel
* @version 1.0.0
* @description Unlocks a channel allowing anyone to join
* @module unlockroom
*/
import {
isModerator,
} from '../utility/_UAC.js';
/**
* Automatically executes once after server is ready
* @param {Object} core - Reference to core environment object
2023-12-22 15:14:03 +08:00
* @public
* @return {void}
*/
export async function init(core) {
if (typeof core.locked === 'undefined') {
core.locked = {};
}
}
/**
* Executes when invoked by a remote client
* @param {Object} env - Environment object with references to core, server, socket & payload
2023-12-22 15:14:03 +08:00
* @public
* @return {void}
*/
export async function run({
core, server, socket, payload,
}) {
// increase rate limit chance and ignore if not admin or mod
if (!isModerator(socket.level)) {
2023-12-27 16:26:49 +08:00
return server.police.frisk(socket, 10);
2023-12-22 15:14:03 +08:00
}
let targetChannel;
if (typeof payload.channel !== 'string') {
if (typeof socket.channel !== 'string') { // @todo Multichannel
return false; // silently fail
}
targetChannel = socket.channel;
} else {
targetChannel = payload.channel;
}
if (!core.locked[targetChannel]) {
return server.reply({
2024-01-09 03:09:59 +08:00
cmd: 'info', // @todo Add numeric info code as `id`
2023-12-22 15:14:03 +08:00
text: 'Channel is not locked.',
channel: socket.channel, // @todo Multichannel
}, socket);
}
core.locked[targetChannel] = false;
server.broadcast({
2024-01-09 03:09:59 +08:00
cmd: 'info', // @todo Add numeric info code as `id`
2023-12-22 15:14:03 +08:00
text: `Channel: ?${targetChannel} unlocked by [${socket.trip}]${socket.nick}`,
channel: targetChannel, // @todo Multichannel, false for global info
}, { channel: targetChannel, level: isModerator });
console.log(`Channel: ?${targetChannel} unlocked by [${socket.trip}]${socket.nick} in ${socket.channel}`);
return true;
}
/**
* Module meta information
* @public
* @typedef {Object} unlockroom/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: 'unlockroom',
category: 'moderators',
description: 'Unlock the current channel you are in or target channel as specified',
usage: `
API: { cmd: 'unlockroom', channel: '<optional target channel>' }`,
};