add kick command and fix typo in .gitignore

merge-requests/8/head
hector6704 2020-04-28 15:24:44 +02:00
parent 74d50b192f
commit a3c82eaf13
No known key found for this signature in database
GPG Key ID: 8D0BA49FAFDDE9B8
3 changed files with 68 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,7 +1,7 @@
# Package Management & Libraries # Package Management & Libraries
node_modules node_modules
yarn.lock yarn.lock
package-json.lock package-lock.json
# Configuration Files # Configuration Files
config.yaml config.yaml

View File

@ -110,4 +110,33 @@ export default class Moderation {
this.client.createMessage(this.logChannels.modlogs, { embed }); this.client.createMessage(this.logChannels.modlogs, { embed });
return mod.save(); return mod.save();
} }
public async kick(user: User, moderator: Member, reason?: string): Promise<ModerationInterface> {
if (reason && reason.length > 512) throw new Error('Kick reason cannot be longer than 512 characters');
await this.client.guilds.get(this.client.config.guildID).kickMember(user.id, reason);
const logID = randomBytes(2).toString('hex');
const mod = new ModerationModel({
userID: user.id,
logID,
moderatorID: moderator.id,
reason: reason || null,
type: 5,
date: new Date(),
});
const embed = new RichEmbed();
embed.setTitle(`Case ${logID} | Kick`);
embed.setColor('#e74c3c');
embed.setAuthor(user.username, user.avatarURL);
embed.setThumbnail(user.avatarURL);
embed.addField('User', `<@${user.id}>`, true);
embed.addField('Moderator', `<@${moderator.id}>`, true);
if (reason) {
embed.addField('Reason', reason, true);
}
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
this.client.createMessage(this.logChannels.modlogs, { embed });
return mod.save();
}
} }

38
src/commands/kick.ts Normal file
View File

@ -0,0 +1,38 @@
import moment, { unitOfTime } from 'moment';
import { Message, User } from 'eris';
import { Client, Command } from '../class';
export default class Kick extends Command {
constructor(client: Client) {
super(client);
this.name = 'kick';
this.description = 'Kicks a member from the guild.';
this.usage = 'kick <member> [reason]';
this.permissions = 3;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
const member = this.client.util.resolveMember(args[0], this.client.guilds.get(this.client.config.guildID));
let user: User;
if (!member) {
try {
user = await this.client.getRESTUser(args[0]);
} catch {
return this.error(message.channel, 'Cannot find user.');
}
}
if (member && !this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.');
message.delete();
const reason: string = args[1];
if (reason.length > 512) return this.error(message.channel, 'Kick reasons cannot be longer than 512 characters.');
await this.client.util.moderation.kick(user, message.member, reason);
return this.success(message.channel, `${user.username}#${user.id} has been kicked.`);
} catch (err) {
return this.client.util.handleError(err, message, this, false);
}
}
}