69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
/* eslint-disable indent */
|
|
const { Infraction } = require('../interfaces/');
|
|
|
|
class RemoveroleInfraction extends Infraction {
|
|
|
|
static type = 'REMOVEROLE';
|
|
|
|
constructor(client, opts = {}) {
|
|
|
|
super(client, {
|
|
targetType: 'USER',
|
|
type: opts.type,
|
|
message: opts.message,
|
|
executor: opts.executor.user,
|
|
target: opts.target.user,
|
|
reason: opts.reason,
|
|
guild: opts.guild,
|
|
channel: opts.channel,
|
|
arguments: opts.arguments,
|
|
silent: opts.silent,
|
|
duration: opts.duration,
|
|
points: opts.points,
|
|
expiration: opts.expiration,
|
|
data: opts.data
|
|
});
|
|
|
|
this.client = client;
|
|
this.member = opts.target;
|
|
this.executorMember = opts.executor;
|
|
|
|
}
|
|
|
|
async execute() {
|
|
|
|
try {
|
|
await this.member.roles.remove(this.data.roleIds, this._reason);
|
|
} catch(error) {
|
|
return this._fail('INFRACTION_ERROR');
|
|
}
|
|
|
|
await this.handle();
|
|
return this._succeed();
|
|
|
|
}
|
|
|
|
async verify() {
|
|
|
|
if (this.guild.ownerID === this.executor.id) return this._succeed();
|
|
const { highest } = this.executorMember.roles;
|
|
const filtered = this.data.roles.filter((r) => r.comparePositionTo(highest) < 0);
|
|
if(filtered.length === 0) {
|
|
return super._fail('C_REMOVEROLE_ROLEHIERARCHY', { plural: filtered.length === 1 ? '' : 's' });
|
|
}
|
|
|
|
this.data.roles = filtered;
|
|
return super._verify();
|
|
|
|
}
|
|
|
|
description(dm) {
|
|
return `\n${this.guild.format('INFRACTION_DESCRIPTIONROLES', {
|
|
plural: this.data.roleIds.length === 1 ? '' : 's',
|
|
roles: dm ? this.data.roleNames.join(', ') : this.data.roleIds.map((r) => `<@&${r}>`).join(' ')
|
|
})}`;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = RemoveroleInfraction; |