galactic-bot/structure/moderation/infractions/Removerole.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-07-16 10:19:31 +02:00
/* eslint-disable indent */
const { Infraction } = require('../interfaces/');
class RemoveroleInfraction extends Infraction {
constructor(client, opts = {}) {
super(client, {
type: 'REMOVEROLE',
targetType: 'user',
message: opts.message,
executor: opts.executor.user,
target: opts.target,
reason: opts.reason || 'N/A',
guild: opts.guild,
channel: opts.channel,
arguments: opts.arguments,
silent: opts.silent,
duration: opts.duration,
color: 0xff3333,
dictionary: {
past: 'removed role from',
present: 'remove role from'
},
points: opts.points,
expiration: opts.expiration,
data: opts.data
});
this.client = client;
2020-07-20 00:42:21 +02:00
this.member = opts.target;
this.executorMember = opts.executor;
2020-07-16 10:19:31 +02:00
}
async execute() {
try {
await this.member.roles.remove(this.data.roles, this._reason);
} catch(error) {
return this._fail('INFRACTION_ERROR');
}
await this.handle();
return this._succeed();
}
async verify() {
2020-07-28 22:40:15 +02:00
const missing = this.guild._checkPermissions(this.message, 'command:removerole');
2020-07-16 10:19:31 +02:00
if(missing.length > 0) {
return super._fail('C_REMOVEROLE_INSUFFICIENTPERMISSIONS');
}
2020-07-28 20:12:38 +02:00
if (this.guild.ownerID === this.executor.id) return this._succeed();
2020-07-20 00:42:21 +02:00
const { highest } = this.executorMember.roles;
2020-07-16 10:19:31 +02:00
const filtered = this.data.roles.filter((r) => r.comparePositionTo(highest) < 0);
if(filtered.length === 0) {
2020-07-20 00:42:21 +02:00
return super._fail('C_REMOVEROLE_ROLEHIERARCHY', { plural: filtered.length === 1 ? '' : 's' });
2020-07-16 10:19:31 +02:00
}
this.data.roles = filtered;
return super._verify();
}
}
module.exports = RemoveroleInfraction;