From b288a5523b4d2cd04e2fc30486c9a46491f7e2e5 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 6 May 2022 13:46:07 +0300 Subject: [PATCH] unresolve --- .../commands/moderation/Unresolve.js | 53 +++++++++++++++++++ src/structure/interfaces/Infraction.js | 14 ++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/structure/components/commands/moderation/Unresolve.js b/src/structure/components/commands/moderation/Unresolve.js index e69de29..57d9d40 100644 --- a/src/structure/components/commands/moderation/Unresolve.js +++ b/src/structure/components/commands/moderation/Unresolve.js @@ -0,0 +1,53 @@ +const { SlashCommand, Infraction } = require("../../../interfaces"); + +/* +, { + name: 'reason', + description: 'Reason for resolving case', + type: 'STRING' + }, { + name: 'notify', + description: 'Attempt to notify the user about the resolve, may not always be possible', + type: 'BOOLEAN' + } +*/ + +class ResolveCommand extends SlashCommand { + + constructor(client) { + super(client, { + name: 'unresolve', + description: 'Unresolve infraction(s). Does not re-apply the infraction\'s action.', + module: 'moderation', + memberPermissions: ['MANAGE_GUILD'], + guildOnly: true, + options: [{ + name: 'case', + type: 'INTEGER', + description: 'Case ID (Integer)', + required: true, + minimum: 0 + }, { + name: 'reason', + description: 'Reason for unresolving case', + type: 'STRING' + }] // Potentially add another option to enable a range of cases + }); + } + + async execute(invoker, { case: caseId, reason, notify }) { + + const { guild, member } = invoker; + const infraction = await new Infraction(this.client, { guild, case: caseId.value }).fetch(true);//.catch(() => null); + if (!infraction) return { emoji: 'failure', index: 'INFRACTION_NOT_FOUND' }; + if (!infraction.resolved) return { emoji: 'failure', index: 'INFRACTION_NOT_RESOLVED' }; + + const response = await infraction.unresolve(member, reason?.value || null, notify?.value || false); + if (response?.error) return { emoji: 'warning', index: 'COMMAND_RESOLVE_WARNING', params: { message: response.message } }; + return { emoji: 'success', index: 'COMMAND_RESOLVE_SUCCESS' }; + + } + +} + +module.exports = ResolveCommand; \ No newline at end of file diff --git a/src/structure/interfaces/Infraction.js b/src/structure/interfaces/Infraction.js index 4baad63..1060cc6 100644 --- a/src/structure/interfaces/Infraction.js +++ b/src/structure/interfaces/Infraction.js @@ -432,8 +432,20 @@ class Infraction { if(notify && this.target) await this.target.send(`Your infraction **#${this.case}** on **${this.guild.name}** was resolved.`); } + async unresolve(staff, reason) { + this.changes.push({ + type: 'RESOLVE', + staff: staff.id, + timestamp: Date.now(), + reason + }); + this.resolved = false; + await this.updateMessages(); + await this.save(); + } + /** - * @param {boolean} [resolveToRightClass=false] Whether the function should instead return + * @param {boolean} [resolveToRightClass=false] Whether the function should instead return the right class for the infraction, used by the resolve command * @return {*} * @memberof Infraction */