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

60 lines
1.5 KiB
JavaScript

const { Infraction } = require('../interfaces/');
const { GuildMember } = require('../../extensions/');
class SoftbanInfraction extends Infraction {
static type = 'SOFTBAN';
constructor(client, opts = {}) {
super(client, {
targetType: 'USER',
message: opts.message,
executor: opts.executor.user,
target: opts.target instanceof GuildMember ? opts.target.user : opts.target,
reason: opts.reason,
guild: opts.guild,
channel: opts.channel,
arguments: opts.arguments,
silent: opts.silent,
points: opts.points,
expiration: opts.expiration,
data: opts.data
});
this.client = client;
}
async execute() {
let days = 1;
if(this.arguments.days) days = this.arguments.days.value;
try {
await this.guild.members.ban(this.target.id, {
reason: this._reason,
days
});
await this.guild.members.unban(this.target.id, this._reason);
} catch(error) {
return this._fail('INFRACTION_ERROR');
}
await this.handle();
return this._succeed();
}
verify() {
if(this.target instanceof GuildMember) {
if(!this.target.bannable) return this._fail('C_SOFTBAN_CANNOTBESOFTBANNED');
}
return super._verify();
}
}
module.exports = SoftbanInfraction;