2020-07-16 10:19:31 +02:00
|
|
|
/* eslint-disable indent */
|
|
|
|
const { Infraction } = require('../interfaces/');
|
|
|
|
|
|
|
|
class AddroleInfraction extends Infraction {
|
|
|
|
|
2021-06-16 06:49:17 +02:00
|
|
|
static type = 'ADDROLE';
|
|
|
|
|
2020-07-16 10:19:31 +02:00
|
|
|
constructor(client, opts = {}) {
|
|
|
|
|
|
|
|
super(client, {
|
2021-05-10 22:09:03 +02:00
|
|
|
targetType: 'USER',
|
2021-06-16 08:50:01 +02:00
|
|
|
type: opts.type,
|
2020-07-16 10:19:31 +02:00
|
|
|
guild: opts.guild,
|
|
|
|
channel: opts.channel,
|
2021-05-10 22:09:03 +02:00
|
|
|
message: opts.message,
|
|
|
|
target: opts.target.user,
|
|
|
|
executor: opts.executor.user,
|
|
|
|
reason: opts.reason,
|
2020-07-16 10:19:31 +02:00
|
|
|
arguments: opts.arguments,
|
|
|
|
silent: opts.silent,
|
|
|
|
duration: opts.duration,
|
|
|
|
points: opts.points,
|
|
|
|
expiration: opts.expiration,
|
2021-06-26 08:42:57 +02:00
|
|
|
data: opts.data,
|
|
|
|
hyperlink: opts.hyperlink
|
2020-07-16 10:19:31 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
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 {
|
2021-05-10 22:09:03 +02:00
|
|
|
await this.member.roles.add(this.data.roleIds, this._reason);
|
2020-07-16 10:19:31 +02:00
|
|
|
} catch(error) {
|
|
|
|
return this._fail('INFRACTION_ERROR');
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.handle();
|
|
|
|
return this._succeed();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async verify() {
|
|
|
|
|
2020-07-28 22:40:15 +02:00
|
|
|
const missingAdministrator = this.channel.permissionsFor(this.guild.me).missing(['ADMINISTRATOR']);
|
|
|
|
let filtered = [];
|
2021-06-26 23:08:04 +02:00
|
|
|
const { highest: clientHighest } = this.guild.me.roles;
|
|
|
|
filtered = this.data.roles.filter((r) => r.comparePositionTo(clientHighest) < 0);
|
|
|
|
console.log("Filtered roles (client)...", filtered.map((r) => r.name).join(', '));
|
2020-07-29 21:01:39 +02:00
|
|
|
if(filtered.length === 0) {
|
|
|
|
return super._fail('C_ADDROLE_ROLEHIERARCHYBOT');
|
|
|
|
}
|
|
|
|
|
2020-07-28 22:40:15 +02:00
|
|
|
if(missingAdministrator.length > 0) {
|
2021-06-26 23:08:04 +02:00
|
|
|
const { highest: memberHighest } = this.executorMember.roles;
|
|
|
|
console.log(memberHighest.map((r) => r.name));
|
|
|
|
filtered = this.data.roles.filter((r) => r.comparePositionTo(memberHighest) < 0);
|
|
|
|
console.log("Filtered roles (member)...", filtered.map((r) => r.name).join(', '));
|
2020-07-28 22:40:15 +02:00
|
|
|
if(filtered.length === 0) {
|
|
|
|
return super._fail('C_ADDROLE_ROLEHIERARCHY');
|
|
|
|
}
|
2020-07-16 10:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.data.roles = filtered;
|
|
|
|
return super._verify();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-10 22:09:03 +02:00
|
|
|
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(' ')
|
|
|
|
})}`;
|
|
|
|
}
|
|
|
|
|
2020-07-16 10:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AddroleInfraction;
|