2021-05-10 22:09:03 +02:00
|
|
|
const { Infraction } = require('../interfaces/');
|
|
|
|
|
2021-06-26 08:42:57 +02:00
|
|
|
const allowedPermissions = ['MANAGE_MESSAGES', 'MANAGE_CHANNELS'];
|
|
|
|
|
2021-05-10 22:09:03 +02:00
|
|
|
class LockdownInfraction extends Infraction {
|
|
|
|
|
2021-06-16 06:49:17 +02:00
|
|
|
static type = 'LOCKDOWN';
|
|
|
|
|
2021-05-10 22:09:03 +02:00
|
|
|
constructor(client, opts = {}) {
|
|
|
|
|
|
|
|
super(client, {
|
2021-06-26 08:42:57 +02:00
|
|
|
targetType: 'CHANNEL',
|
2021-06-16 08:50:01 +02:00
|
|
|
type: opts.type,
|
2021-05-10 22:09:03 +02:00
|
|
|
message: opts.message,
|
|
|
|
executor: opts.executor.user,
|
2021-06-26 08:42:57 +02:00
|
|
|
target: opts.target,
|
2021-05-10 22:09:03 +02:00
|
|
|
reason: opts.reason,
|
|
|
|
guild: opts.guild,
|
|
|
|
channel: opts.channel,
|
|
|
|
arguments: opts.arguments,
|
|
|
|
silent: opts.silent,
|
2021-06-26 08:42:57 +02:00
|
|
|
duration: opts.duration,
|
|
|
|
data: opts.data,
|
|
|
|
hyperlink: opts.hyperlink
|
2021-05-10 22:09:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.client = client;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async execute() {
|
2021-06-26 08:42:57 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
};
|
2021-05-10 22:09:03 +02:00
|
|
|
|
2021-06-26 08:42:57 +02:00
|
|
|
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
|
|
|
|
});
|
2021-05-10 22:09:03 +02:00
|
|
|
|
|
|
|
await this.handle();
|
|
|
|
return this._succeed();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async verify() {
|
|
|
|
|
|
|
|
return super._verify();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = LockdownInfraction;
|