mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
7ecb31c46c
Fleshing out the new channel ownership feature, along with a typo fix and small syntax updates. A claim can now be staked with /claimchannel, a channel owner may change a trip's level using /setlevel To do: unclaimchannel, setmotd, makeprivate, makepublic, renewclaim, garbage keeping, update mod commands to accept channelOwner and channelModerator, etc
90 lines
2.3 KiB
JavaScript
90 lines
2.3 KiB
JavaScript
/* 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
|
|
* @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
|
|
* @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)) {
|
|
return server.police.frisk(socket, 10);
|
|
}
|
|
|
|
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({
|
|
cmd: 'info',
|
|
text: 'Channel is not locked.',
|
|
channel: socket.channel, // @todo Multichannel
|
|
}, socket);
|
|
}
|
|
|
|
core.locked[targetChannel] = false;
|
|
|
|
server.broadcast({
|
|
cmd: 'info',
|
|
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>' }`,
|
|
};
|