fix various issues with ban/unban commands
parent
563db7d9a7
commit
4069a20a31
|
@ -1,5 +1,5 @@
|
||||||
import moment, { unitOfTime } from 'moment';
|
import moment, { unitOfTime } from 'moment';
|
||||||
import { Message } from 'eris';
|
import { Message, User } from 'eris';
|
||||||
import { Client, Command } from '../class';
|
import { Client, Command } from '../class';
|
||||||
|
|
||||||
export default class Ban extends Command {
|
export default class Ban extends Command {
|
||||||
|
@ -17,16 +17,35 @@ export default class Ban extends Command {
|
||||||
try {
|
try {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const member = this.client.util.resolveMember(args[0], message.channel.guild);
|
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.***`);
|
let user: User;
|
||||||
if (!this.client.util.moderation.checkPermissions(member, message.member)) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Permission denied.***`);
|
if (!member) {
|
||||||
|
try {
|
||||||
|
user = await this.client.getRESTUser(args[0]);
|
||||||
|
} catch {
|
||||||
|
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Cannot find user.***`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.client.guilds.get(this.client.config.guildID).getBan(args[0]);
|
||||||
|
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} This user is already banned.***`);
|
||||||
|
} catch {
|
||||||
|
// eslint-disable-next-line no-unused-expressions
|
||||||
|
undefined;
|
||||||
|
}
|
||||||
|
if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Permission denied.***`);
|
||||||
message.delete();
|
message.delete();
|
||||||
|
|
||||||
|
let momentMilliseconds: number;
|
||||||
|
let reason: string;
|
||||||
|
if (args.length > 1) {
|
||||||
const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi);
|
const lockLength = args[1].match(/[a-z]+|[^a-z]+/gi);
|
||||||
const length = Number(lockLength[0]);
|
const length = Number(lockLength[0]);
|
||||||
const unit = lockLength[1] as unitOfTime.Base;
|
const unit = lockLength[1] as unitOfTime.Base;
|
||||||
const momentMilliseconds = moment.duration(length, unit).asMilliseconds();
|
momentMilliseconds = moment.duration(length, unit).asMilliseconds();
|
||||||
const reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ');
|
reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ');
|
||||||
return await this.client.util.moderation.ban(member, message.member, momentMilliseconds, reason);
|
}
|
||||||
|
await this.client.util.moderation.ban(user, message.member, momentMilliseconds, reason);
|
||||||
|
return message.channel.createMessage(`***${this.client.util.emojis.SUCCESS} ${user.username}#${user.id} has been banned.***`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return this.client.util.handleError(err, message, this, false);
|
return this.client.util.handleError(err, message, this, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,20 @@ export default class Unban extends Command {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let user: User;
|
let user: User;
|
||||||
try {
|
try {
|
||||||
await this.client.getRESTUser(args[0]);
|
user = await this.client.getRESTUser(args[0]);
|
||||||
} catch {
|
} catch {
|
||||||
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Could find find user.***`);
|
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Could find find user.***`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (await this.client.getRESTGuildMember(this.client.config.guildID, args[0])) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} This member exists in the server.***`);
|
if (await this.client.getRESTGuildMember(this.client.config.guildID, args[0])) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} This member exists in the server.***`);
|
||||||
} catch {
|
} catch {
|
||||||
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} This member exists in the server.***`);
|
// eslint-disable-next-line no-unused-expressions
|
||||||
|
undefined;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.client.guilds.get(this.client.config.guildID).getBan(args[0]);
|
||||||
|
} catch {
|
||||||
|
return message.channel.createMessage(`***${this.client.util.emojis.ERROR} This user is not banned.***`);
|
||||||
}
|
}
|
||||||
if (!user) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Unable to locate user.***`);
|
if (!user) return message.channel.createMessage(`***${this.client.util.emojis.ERROR} Unable to locate user.***`);
|
||||||
message.delete();
|
message.delete();
|
||||||
|
|
Loading…
Reference in New Issue