fixed lockdown infraction never actually finishing

This commit is contained in:
Erik 2022-06-28 13:51:57 +03:00
parent 555dc536ce
commit 1758024c4c
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -30,13 +30,17 @@ class LockdownInfraction extends Infraction {
async execute() {
const permissions = this.target.permissionOverwrites;
const everyoneRole = this.guild.roles.everyone;
this.data.oldPermissions = {};
for (const permission of permissions.cache.values()) {
const overwrites = [...permissions.cache.values()];
const newOverwrites = [];
for (const permission of overwrites) {
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;
// console.log(`Doing ${permission.id}: ${permission.type}`);
this.data.oldPermissions[permission.id] = {
type: permission.type,
@ -46,25 +50,72 @@ class LockdownInfraction extends Infraction {
}
};
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;
const allowed = permission.allow.toArray();
const denied = permission.deny.toArray();
if (permission.allow.has('SEND_MESSAGES')) {
this.data.oldPermissions[permission.id].permissions.SEND_MESSAGES = true;
allowed.splice(allowed.indexOf('SEND_MESSAGES'), 1);
denied.push('SEND_MESSAGES');
}
if (permission.allow.has('ADD_REACTIONS')) {
this.data.oldPermissions[permission.id].permissions.ADD_REACTIONS = true;
allowed.splice(allowed.indexOf('ADD_REACTIONS'), 1);
denied.push('ADD_REACTIONS');
}
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 permissions.edit(permission.id, {
SEND_MESSAGES: false,
ADD_REACTIONS: false
}, { type: permission.type === 'role' ? 0 : 1, reason: this._reason });
} catch (error) {
this._fail();
}
newOverwrites.push({
id: permission.id,
allow: allowed,
deny: denied,
type: permission.type
});
// try {
// await permissions.edit(permission.id, {
// SEND_MESSAGES: false,
// ADD_REACTIONS: false
// }, { type: permission.type === 'role' ? 0 : 1, reason: this._reason });
// } catch (error) {
// this._fail();
// }
// console.log(this.data.oldPermissions[permission.id]);
}
await permissions.edit(this.client.user.id, {
SEND_MESSAGES: true,
ADD_REACTIONS: true
}, { type: 1 });
// The everyone role won't be edited unless it has any changes, so ensure it has been processed
if (!this.data.oldPermissions[everyoneRole.id]) {
this.data.oldPermissions[everyoneRole.id] = {
type: 'role',
permissions: {
SEND_MESSAGES: null,
ADD_REACTIONS: null
}
};
newOverwrites.push({
id: everyoneRole.id,
deny: ['SEND_MESSAGES', 'ADD_REACTIONS'],
type: 'role'
});
// await permissions.create(permissions.id, {
// SEND_MESSAGES: false,
// ADD_REACTIONS: false
// }, { type: 0, reason: this._reason });
}
// console.log(this.data);
// Ensures the bot can still send messages
// await permissions.edit(this.client.user.id, {
// SEND_MESSAGES: true,
// ADD_REACTIONS: true
// }, { type: 1 });
newOverwrites.push({
id: this.client.user.id,
allow: ['SEND_MESSAGES', 'ADD_REACTIONS']
});
await permissions.set(newOverwrites, this._reason);
await this.handle();
return this._succeed();