unresolve

This commit is contained in:
Erik 2022-05-06 13:46:07 +03:00
parent d961174426
commit b288a5523b
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 66 additions and 1 deletions

View File

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

View File

@ -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
*/