This commit is contained in:
Erik 2022-07-22 11:51:10 +03:00
parent 1a68e23548
commit c6bc30f9c0
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
8 changed files with 19 additions and 16 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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`;

View File

@ -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();

View File

@ -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 });
}

View File

@ -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();

View File

@ -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, {

View File

@ -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);