From c6bc30f9c079d66172de8d2cc3632db1746ec9e2 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 22 Jul 2022 11:51:10 +0300 Subject: [PATCH] bugfix --- src/structure/client/ModerationManager.js | 15 +++++++++------ src/structure/components/infractions/Ban.js | 4 ++-- src/structure/components/infractions/Mute.js | 4 ++-- src/structure/components/infractions/Unban.js | 2 +- .../components/infractions/Unlockdown.js | 4 ++-- src/structure/components/infractions/Unmute.js | 2 +- src/structure/components/observers/AuditLog.js | 2 +- src/structure/interfaces/Infraction.js | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/structure/client/ModerationManager.js b/src/structure/client/ModerationManager.js index aea5323..cac92a5 100644 --- a/src/structure/client/ModerationManager.js +++ b/src/structure/client/ModerationManager.js @@ -430,7 +430,7 @@ class ModerationManager { // this.logger.error(`Error during update of infraction:\n${e.stack || e}`); // }); // this.callbacks.delete(i.id); - await this.removeCallback(this.callbacks.get(i.id), true); + await this.removeCallback(i, true); return true; @@ -458,17 +458,20 @@ class ModerationManager { } - async removeCallback(callback, updateCase = false) { + async removeCallback(infraction, updateCase = false) { // if(!callback) return; - this.logger.debug(`Removing callback ${callback.infraction.type} for ${callback.infraction.targetType} ${callback.infraction.target}.`); + this.logger.debug(`Removing callback ${infraction.type} for ${infraction.targetType} ${infraction.target}.`); if(updateCase) await this.client.storageManager.mongodb.infractions.updateOne( - { id: callback.infraction.id }, + { id: infraction.id }, { _callbacked: true } ).catch((e) => { this.logger.error(`Error during update of infraction:\n${e.stack || e}`); }); - clearTimeout(callback.timeout); - this.callbacks.delete(callback.infraction.id); + const cb = this.callbacks.get(infraction.id); + if (cb) { + clearTimeout(cb.timeout); + this.callbacks.delete(infraction.id); + } } async _fetchTarget(guild, targetId, targetType, user = false) { diff --git a/src/structure/components/infractions/Ban.js b/src/structure/components/infractions/Ban.js index 74211ea..c3efa87 100644 --- a/src/structure/components/infractions/Ban.js +++ b/src/structure/components/infractions/Ban.js @@ -48,7 +48,7 @@ class BanInfraction extends Infraction { const callbacks = this.client.moderationManager.callbacks.filter((c) => c.infraction.type === 'BAN' && c.infraction.target === this.target.id); - if (callbacks.size > 0) callbacks.map((c) => this.client.moderationManager.removeCallback(c)); + if (callbacks.size > 0) callbacks.map((c) => this.client.moderationManager.removeCallback(c.infraction)); return this._succeed(); @@ -74,7 +74,7 @@ class BanInfraction extends Infraction { async resolve(...args) { // const infraction = await this.client.moderationManager.findLatestInfraction(this.type, this.targetId); const callback = this.client.moderationManager.callbacks.get(this.id); - if (callback) this.client.moderationManager.removeCallback(callback); + if (callback) this.client.moderationManager.removeCallback(callback.infraction); const banned = await this.guild.bans.fetch(this.targetId).catch(() => null); if (banned) { diff --git a/src/structure/components/infractions/Mute.js b/src/structure/components/infractions/Mute.js index 6e063a3..cd12b5d 100644 --- a/src/structure/components/infractions/Mute.js +++ b/src/structure/components/infractions/Mute.js @@ -107,7 +107,7 @@ class MuteInfraction extends Infraction { if (callback) { this.data.removedRoles = [...new Set([...this.data.removedRoles, ...callback.infraction.data.removedRoles])]; - this.client.moderationManager.removeCallback(callback); + this.client.moderationManager.removeCallback(callback.infraction); } // if(callbacks.size > 0) callbacks.map((c) => this.client.moderationManager._removeExpiration(c)); @@ -156,7 +156,7 @@ class MuteInfraction extends Infraction { const { removedRoles, muteType, muteRole } = this.data; const member = await this.guild.memberWrapper(this.targetId).catch(() => null); const callback = await member.getCallback(this.type); - if (callback) this.client.moderationManager.removeCallback(callback); + if (callback) this.client.moderationManager.removeCallback(callback.infraction); if (inf.id === this.id && member) { const reason = `Case ${this.case} resolve`; diff --git a/src/structure/components/infractions/Unban.js b/src/structure/components/infractions/Unban.js index ee70c63..a9234f2 100644 --- a/src/structure/components/infractions/Unban.js +++ b/src/structure/components/infractions/Unban.js @@ -39,7 +39,7 @@ class UnbanInfraction extends Infraction { const callbacks = this.client.moderationManager.callbacks.filter((c) => c.infraction.type === 'BAN' && c.infraction.target === this.target.id); - if (callbacks.size > 0) callbacks.map((c) => this.client.moderationManager.removeCallback(c)); + if (callbacks.size > 0) callbacks.map((c) => this.client.moderationManager.removeCallback(c.infraction)); await this.handle(); return this._succeed(); diff --git a/src/structure/components/infractions/Unlockdown.js b/src/structure/components/infractions/Unlockdown.js index b13c307..3e01344 100644 --- a/src/structure/components/infractions/Unlockdown.js +++ b/src/structure/components/infractions/Unlockdown.js @@ -79,12 +79,12 @@ class UnlockdownInfraction extends Infraction { } - const result = await permissions.set(newOverwrites, this._reason).catch((err) => console.error(err)); + const result = await permissions.set(newOverwrites, this._reason).catch(() => null); if(!result) return this._fail(); if (latest) { const callback = this.client.moderationManager.callbacks.get(latest.id); - if (callback) await this.client.moderationManager.removeCallback(callback, true); + if (callback) await this.client.moderationManager.removeCallback(callback.infraction, true); else await this.client.mongodb.infractions.updateOne({ id: latest.id }, { _callbacked: true }); } diff --git a/src/structure/components/infractions/Unmute.js b/src/structure/components/infractions/Unmute.js index 5f3983e..38b08cf 100644 --- a/src/structure/components/infractions/Unmute.js +++ b/src/structure/components/infractions/Unmute.js @@ -117,7 +117,7 @@ class UnmuteInfraction extends Infraction { break; } - if(callback) this.client.moderationManager.removeCallback(callback, true); + if(callback) this.client.moderationManager.removeCallback(callback.infraction, true); await this.handle(); return this._succeed(); diff --git a/src/structure/components/observers/AuditLog.js b/src/structure/components/observers/AuditLog.js index 744068a..84e4465 100644 --- a/src/structure/components/observers/AuditLog.js +++ b/src/structure/components/observers/AuditLog.js @@ -102,7 +102,7 @@ class AuditLogObserver extends Observer { if (type === 'UNMUTE') { const callback = this.client.moderation.callbacks.filter((cb) => cb.infraction.target === newMember.id && cb.infraction.type === 'MUTE').first(); - if(callback) this.client.moderation.removeCallback(callback, true); + if (callback) this.client.moderation.removeCallback(callback.infraction, true); } new Infraction(this.client, { diff --git a/src/structure/interfaces/Infraction.js b/src/structure/interfaces/Infraction.js index 3b8810b..0f72f65 100644 --- a/src/structure/interfaces/Infraction.js +++ b/src/structure/interfaces/Infraction.js @@ -421,7 +421,7 @@ class Infraction { await member.timeout(time < 0 ? null : time, `Duration edit of case ${this.case}`); } - if(callback) await this.client.moderationManager.removeCallback(callback); + if (callback) await this.client.moderationManager.removeCallback(callback.infraction); await this.client.moderationManager.handleCallbacks([this.json]); this.changes.push(log);