diff --git a/structure/moderation/ModerationManager.js b/structure/moderation/ModerationManager.js index c7bcdcc..c6f0566 100644 --- a/structure/moderation/ModerationManager.js +++ b/structure/moderation/ModerationManager.js @@ -291,75 +291,27 @@ class ModerationManager { let points = 0, expiration = 0, response = null; - const { force } = action; - const Infraction = Constant.Infractions[action.type]; - + const { force, duration, type } = action; + const Infraction = Constant.Infractions[type]; + if (moderationPoints.enabled) { - points = action.points || moderationPoints.points[action.type]; - expiration = action.expiration || moderationPoints.expirations[action.type]; + points = action.points || moderationPoints.points[type]; + expiration = action.expiration || moderationPoints.expirations[type]; } - const infractionData = { - executor: guild.me, + response = await this._handleTarget(Infraction, message.member, { guild, channel: message.channel, - message, - target: message.member, + executor: guild.me, + arguments: null, reason, - duration: action.duration, - silent, + duration: duration, data, - points, - expiration - }; + force, + silent + }); - const infraction = new Infraction(this.client, infractionData); - - const verification = await infraction.verify(); - if (verification.error) { - this.client.logger.debug(`Automod infraction failed verification.\n${infraction.type}:\n${JSON.stringify(infractionData)}`); - return; // Possibly add a automod error log channel setting and do something here -- skip for now - } - - if (autoModeration.enabled && points && !force) { - - const userTarget = message.author; - const oldPoints = await userTarget.totalPoints(guild); - const newPoints = oldPoints + points; - - let result = null; - // eslint-disable-next-line prefer-const - for (let [threshold, action] of Object.entries(autoModeration.thresholds)) { - threshold = parseInt(threshold); - if (oldPoints >= threshold) continue; - if (newPoints >= threshold) result = { - threshold, - ...action - }; - } - - if (result && Constant.Hierarchy[infraction.type] <= Constant.Hierarchy[result.type]) { - infractionData.duration = result.length; - infractionData.reason += `\n*${message.format('INFRACTION_AUTOMODESCALATION')}*`; - const escalation = new Constant.Infractions[result.type](this.client, infractionData); - - const verification = await escalation.verify(); - if (verification.error) { - this.client.logger.debug(`Automod escalated infraction failed verification.\n${infraction.type}:\n${JSON.stringify(infractionData)}`); - return; // Possibly add a automod error log channel setting and do something here -- skip for now - } - //: moderationPoints.expirations[escalation.type] - escalation.totalPoints = await userTarget.totalPoints(guild, { points, expiration, timestamp: infraction.timestamp }); - - response = await escalation.execute(); - - } else { - infraction.totalPoints = await userTarget.totalPoints(guild, { points, expiration, timestamp: infraction.timestamp }); - } - - } - - if (!response) response = await infraction.execute(); + console.log(response) if (response.error) this.client.logger.debug(`Automod infraction execution failed:\n${JSON.stringify(response)}`); // TODO: