Lockdown & unlockdown
This commit is contained in:
parent
2beeabb739
commit
88a9712f73
@ -88,4 +88,13 @@ Cannot edit duration of a non-timed infraction.
|
||||
|
||||
//Nickname Command
|
||||
[INFRACTION_DESCRIPTIONNICKNAME]
|
||||
**Old Name:** {old} | **New Name:** {new}
|
||||
**Old Name:** {old} | **New Name:** {new}
|
||||
|
||||
[INFRACTION_UNLOCKDOWN_NOTLOCKED]
|
||||
The channel isn't locked down.
|
||||
|
||||
[INFRACTION_LOCKDOWN_EXISTING]
|
||||
The channel is already locked down.
|
||||
Use `/unlockdown` to unlock it.
|
||||
|
||||
If you've manually reverted the lockdown, resolve case **#{case}**.
|
@ -29,6 +29,11 @@ class LockdownInfraction extends Infraction {
|
||||
|
||||
async execute() {
|
||||
|
||||
const existing = await this.client.moderationManager.findLatestInfraction('LOCKDOWN', this.target);
|
||||
if (!existing._callbacked && !existing.resolved) {
|
||||
return this._fail({ message: this.guild.format('INFRACTION_LOCKDOWN_EXISTING', { case: existing.case }) });
|
||||
}
|
||||
|
||||
const permissions = this.target.permissionOverwrites;
|
||||
const everyoneRole = this.guild.roles.everyone;
|
||||
|
||||
@ -39,8 +44,11 @@ class LockdownInfraction extends Infraction {
|
||||
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}`);
|
||||
if (roleOrMember && roleOrMember.permissions.has(allowedPermissions)) {
|
||||
newOverwrites.push(permission);
|
||||
continue;
|
||||
}
|
||||
//console.log(`Doing ${permission.id} (${roleOrMember.name || roleOrMember.tag}): ${permission.type}`);
|
||||
|
||||
this.data.oldPermissions[permission.id] = {
|
||||
type: permission.type,
|
||||
@ -57,14 +65,15 @@ class LockdownInfraction extends Infraction {
|
||||
this.data.oldPermissions[permission.id].permissions.SEND_MESSAGES = true;
|
||||
allowed.splice(allowed.indexOf('SEND_MESSAGES'), 1);
|
||||
denied.push('SEND_MESSAGES');
|
||||
}
|
||||
} else if (permission.deny.has('SEND_MESSAGES')) this.data.oldPermissions[permission.id].permissions.SEND_MESSAGES = false;
|
||||
else 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;
|
||||
} else if (permission.deny.has('ADD_REACTIONS')) this.data.oldPermissions[permission.id].permissions.ADD_REACTIONS = false;
|
||||
else denied.push('ADD_REACTIONS');
|
||||
|
||||
|
||||
newOverwrites.push({
|
||||
@ -110,9 +119,15 @@ class LockdownInfraction extends Infraction {
|
||||
// SEND_MESSAGES: true,
|
||||
// ADD_REACTIONS: true
|
||||
// }, { type: 1 });
|
||||
newOverwrites.push({
|
||||
const index = newOverwrites.findIndex((entry) => entry.id === this.client.user.id);
|
||||
if (index >= 0) {
|
||||
if (!newOverwrites[index].allow.has('SEND_MESSAGES'))
|
||||
newOverwrites[index].allow.add('SEND_MESSAGES');
|
||||
if (newOverwrites[index].deny.has('SEND_MESSAGES'))
|
||||
newOverwrites[index].deny.remove('SEND_MESSAGES');
|
||||
} else newOverwrites.push({
|
||||
id: this.client.user.id,
|
||||
allow: ['SEND_MESSAGES', 'ADD_REACTIONS']
|
||||
allow: ['SEND_MESSAGES']
|
||||
});
|
||||
|
||||
await permissions.set(newOverwrites, this._reason);
|
||||
|
@ -12,7 +12,7 @@ class UnlockdownInfraction extends Infraction {
|
||||
type: opts.type,
|
||||
invoker: opts.invoker,
|
||||
executor: opts.executor.user,
|
||||
target: opts.target.user,
|
||||
target: opts.target,
|
||||
reason: opts.reason,
|
||||
guild: opts.guild,
|
||||
channel: opts.channel,
|
||||
@ -22,17 +22,67 @@ class UnlockdownInfraction extends Infraction {
|
||||
hyperlink: opts.hyperlink
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
async execute() {
|
||||
|
||||
const callback = await this.client.moderationManager.callbacks.filter((c) => {
|
||||
return c.infraction.type === this.type
|
||||
&& c.infraction.target === this.targetId;
|
||||
}).first();
|
||||
// const callback = await this.client.moderationManager.callbacks.filter((c) => {
|
||||
// return c.infraction.type === this.type
|
||||
// && c.infraction.target === this.targetId;
|
||||
// }).first();
|
||||
|
||||
if (!callback) await this.handle();
|
||||
let latest = null;
|
||||
if (!this.data) {
|
||||
latest = await this.client.moderationManager.findLatestInfraction('LOCKDOWN', this.target);
|
||||
if (latest._callbacked || latest.resolved) return this._fail({ message: this.guild.format('INFRACTION_UNLOCKDOWN_NOTLOCKED') });
|
||||
}
|
||||
|
||||
const data = latest?.data || this.data;
|
||||
const oldPerms = data.oldPermissions;
|
||||
const permissions = this.target.permissionOverwrites;
|
||||
const overwrites = [...permissions.cache.values()];
|
||||
const newOverwrites = [];
|
||||
|
||||
for (const permission of overwrites) {
|
||||
|
||||
if (!oldPerms[permission.id]) {
|
||||
newOverwrites.push(permission);
|
||||
continue;
|
||||
}
|
||||
|
||||
const allowed = permission.allow.toArray();
|
||||
const denied = permission.deny.toArray();
|
||||
const old = oldPerms[permission.id].permissions;
|
||||
|
||||
if (old.SEND_MESSAGES === null) denied.splice(denied.indexOf('SEND_MESSAGES'), 1);
|
||||
if (old.ADD_REACTIONS === null) denied.splice(denied.indexOf('ADD_REACTIONS'), 1);
|
||||
|
||||
if (old.SEND_MESSAGES) {
|
||||
denied.splice(denied.indexOf('SEND_MESSAGES'), 1);
|
||||
allowed.push('SEND_MESSAGES');
|
||||
}
|
||||
if (old.ADD_REACTIONS) {
|
||||
denied.splice(denied.indexOf('ADD_REACTIONS'), 1);
|
||||
allowed.push('ADD_REACTIONS');
|
||||
}
|
||||
|
||||
newOverwrites.push({
|
||||
id: permission.id,
|
||||
allow: allowed,
|
||||
deny: denied,
|
||||
type: permission.type
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
await permissions.set(newOverwrites, this._reason);
|
||||
|
||||
if (latest) {
|
||||
const callback = this.client.moderationManager.callbacks.get(latest.id);
|
||||
await this.client.moderationManager.removeCallback(callback, true);
|
||||
}
|
||||
|
||||
await this.handle();
|
||||
return this._succeed();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user