cardboardbox/commands/Moderation/lockdown.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-02-06 19:25:27 +00:00
const ms = require('ms');
exports.run = async (client, message, args, level) => {
if (!client.lockit) client.lockit = [];
const time = args.join(' ');
const validUnlocks = ['release', 'unlock'];
if (!time) return message.reply('you must set a duration for the lockdown in either hours, minutes or seconds.');
if (validUnlocks.includes(time)) {
message.channel.overwritePermissions(message.guild.id, {
SEND_MESSAGES: null
}).then(() => {
message.channel.send('Lockdown has been lifted.');
clearTimeout(client.lockit[message.channel.id]);
delete client.lockit[message.channel.id];
}).catch(error => {
console.log(error);
});
} else {
message.channel.overwritePermissions(message.guild.id, {
SEND_MESSAGES: false
}).then(() => {
message.channel.send(`Channel has been locked down for ${ms(ms(time), { long:true })}.`).then(() => {
client.lockit[message.channel.id] = setTimeout(() => {
message.channel.overwritePermissions(message.guild.id, {
SEND_MESSAGES: null
}).then(message.channel.send('Lockdown has been lifted.')).catch(console.error);
delete client.lockit[message.channel.id];
}, ms(time));
}).catch(error => {
console.log(error);
});
});
}
};
exports.conf = {
enabled: true,
guildOnly: true,
aliases: ["ld"],
permLevel: "Administrator"
};
exports.help = {
name: "lockdown",
category: "Moderation",
description: "People being a pest somewhere? Lock it down!",
usage: "lockdown [duration]"
};