2020-04-15 15:13:16 -04:00
|
|
|
import moment, { unitOfTime } from 'moment';
|
|
|
|
import { Message } from 'eris';
|
|
|
|
import { Client, Command } from '../class';
|
|
|
|
|
|
|
|
export default class Ban extends Command {
|
|
|
|
constructor(client: Client) {
|
|
|
|
super(client);
|
|
|
|
this.name = 'ban';
|
|
|
|
this.description = 'Bans a member from the guild.';
|
2020-04-15 15:33:46 -04:00
|
|
|
this.usage = 'ban <member> [time] [reason]';
|
2020-04-15 15:13:16 -04:00
|
|
|
this.permissions = 2;
|
|
|
|
this.guildOnly = true;
|
|
|
|
this.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async run(message: Message, args: string[]) {
|
|
|
|
try {
|
|
|
|
// @ts-ignore
|
|
|
|
const member = this.client.util.resolveMember(args[0], message.channel.guild);
|
|
|
|
if (!member) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Cannot find member.***`);
|
|
|
|
if (!this.client.util.moderation.checkPermissions(member, message.member)) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Permission denied.***`);
|
|
|
|
message.delete();
|
|
|
|
|
|
|
|
const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi);
|
|
|
|
const length = Number(lockLength[0]);
|
|
|
|
const unit = lockLength[1] as unitOfTime.Base;
|
|
|
|
const momentMilliseconds = moment.duration(length, unit).asMilliseconds();
|
|
|
|
const reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ');
|
|
|
|
return await this.client.util.moderation.ban(member, message.member, momentMilliseconds, reason);
|
|
|
|
} catch (err) {
|
2020-04-15 15:33:46 -04:00
|
|
|
return this.client.util.handleError(err, message, this, false);
|
2020-04-15 15:13:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|