81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
const { Infraction } = require('../interfaces/');
|
|
|
|
const allowedPermissions = ['MANAGE_MESSAGES', 'MANAGE_CHANNELS'];
|
|
|
|
class LockdownInfraction extends Infraction {
|
|
|
|
static type = 'LOCKDOWN';
|
|
|
|
constructor(client, opts = {}) {
|
|
|
|
super(client, {
|
|
targetType: 'CHANNEL',
|
|
type: opts.type,
|
|
message: opts.message,
|
|
executor: opts.executor.user,
|
|
target: opts.target,
|
|
reason: opts.reason,
|
|
guild: opts.guild,
|
|
channel: opts.channel,
|
|
arguments: opts.arguments,
|
|
silent: opts.silent,
|
|
duration: opts.duration,
|
|
data: opts.data,
|
|
hyperlink: opts.hyperlink
|
|
});
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
async execute() {
|
|
|
|
const permissions = this.target.permissionOverwrites;
|
|
|
|
this.data.oldPermissions = {};
|
|
for(const permission of permissions.values()) {
|
|
const roleOrMember = permission.type === 'role' ? await this.guild.roles.fetch(permission.id) : await this.guild.members.fetch(permission.id);
|
|
if(roleOrMember && roleOrMember.permissions.has(allowedPermissions)) continue;
|
|
|
|
this.data.oldPermissions[permission.id] = {
|
|
type: permission.type,
|
|
permissions: {
|
|
SEND_MESSAGES: null,
|
|
ADD_REACTIONS: null
|
|
}
|
|
};
|
|
|
|
if(permission.allow.has('SEND_MESSAGES')) this.data.oldPermissions[permission.id].permissions.SEND_MESSAGES = true;
|
|
if(permission.allow.has('ADD_REACTIONS')) this.data.oldPermissions[permission.id].permissions.ADD_REACTIONS = true;
|
|
if(permission.deny.has('SEND_MESSAGES')) this.data.oldPermissions[permission.id].permissions.SEND_MESSAGES = false;
|
|
if(permission.deny.has('ADD_REACTIONS')) this.data.oldPermissions[permission.id].permissions.ADD_REACTIONS = false;
|
|
|
|
try {
|
|
await this.target.updateOverwrite(permission.id, {
|
|
SEND_MESSAGES: false,
|
|
ADD_REACTIONS: false
|
|
}, this._reason);
|
|
} catch(error) {
|
|
this._fail();
|
|
}
|
|
}
|
|
|
|
await this.target.updateOverwrite(this.client.user.id, {
|
|
SEND_MESSAGES: true,
|
|
ADD_REACTIONS: true
|
|
});
|
|
|
|
await this.handle();
|
|
return this._succeed();
|
|
|
|
}
|
|
|
|
async verify() {
|
|
|
|
return super._verify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = LockdownInfraction; |