2020-04-15 15:13:16 -04:00
|
|
|
import moment, { unitOfTime } from 'moment';
|
2020-04-16 22:56:52 -04:00
|
|
|
import { Message, User, PrivateChannel, GroupChannel } from 'eris';
|
2020-04-15 15:13:16 -04:00
|
|
|
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 {
|
2020-04-16 22:56:52 -04:00
|
|
|
const member = this.client.util.resolveMember(args[0], message.member.guild);
|
2020-04-16 17:58:10 -04:00
|
|
|
let user: User;
|
|
|
|
if (!member) {
|
|
|
|
try {
|
|
|
|
user = await this.client.getRESTUser(args[0]);
|
|
|
|
} catch {
|
2020-04-16 22:56:52 -04:00
|
|
|
return this.error(message.channel, 'Cannot find user.');
|
2020-04-16 17:58:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
await this.client.guilds.get(this.client.config.guildID).getBan(args[0]);
|
2020-04-16 22:56:52 -04:00
|
|
|
return this.error(message.channel, 'This user is already banned.');
|
|
|
|
} catch {} // eslint-disable-line no-empty
|
|
|
|
if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.');
|
2020-04-15 15:13:16 -04:00
|
|
|
message.delete();
|
|
|
|
|
2020-04-16 17:58:10 -04:00
|
|
|
let momentMilliseconds: number;
|
|
|
|
let reason: string;
|
|
|
|
if (args.length > 1) {
|
|
|
|
const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi);
|
|
|
|
const length = Number(lockLength[0]);
|
|
|
|
const unit = lockLength[1] as unitOfTime.Base;
|
|
|
|
momentMilliseconds = moment.duration(length, unit).asMilliseconds();
|
|
|
|
reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ');
|
2020-04-16 22:56:52 -04:00
|
|
|
if (reason.length > 512) return this.error(message.channel, 'Ban reasons cannot be longer than 512 characters.');
|
2020-04-16 17:58:10 -04:00
|
|
|
}
|
|
|
|
await this.client.util.moderation.ban(user, message.member, momentMilliseconds, reason);
|
2020-04-16 22:56:52 -04:00
|
|
|
return this.success(message.channel, `${user.username}#${user.id} has been banned.`);
|
2020-04-15 15:13:16 -04:00
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|