From a3c82eaf13fda1f78e9f35959348f77bd271e3e4 Mon Sep 17 00:00:00 2001 From: hector6704 Date: Tue, 28 Apr 2020 15:24:44 +0200 Subject: [PATCH 1/2] add kick command and fix typo in .gitignore --- .gitignore | 2 +- src/class/Moderation.ts | 29 +++++++++++++++++++++++++++++ src/commands/kick.ts | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/commands/kick.ts diff --git a/.gitignore b/.gitignore index 99dbe56..196dea3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Package Management & Libraries node_modules yarn.lock -package-json.lock +package-lock.json # Configuration Files config.yaml diff --git a/src/class/Moderation.ts b/src/class/Moderation.ts index e7d3975..0f730d9 100644 --- a/src/class/Moderation.ts +++ b/src/class/Moderation.ts @@ -110,4 +110,33 @@ export default class Moderation { this.client.createMessage(this.logChannels.modlogs, { embed }); return mod.save(); } + + public async kick(user: User, moderator: Member, reason?: string): Promise { + 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(); + } } diff --git a/src/commands/kick.ts b/src/commands/kick.ts new file mode 100644 index 0000000..72e2574 --- /dev/null +++ b/src/commands/kick.ts @@ -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 [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); + } + } +} From 33fb4a24dfb176e9560009bb4bdaedb8f9633ea2 Mon Sep 17 00:00:00 2001 From: hector6704 Date: Fri, 1 May 2020 16:27:32 +0200 Subject: [PATCH 2/2] remove useless import --- src/commands/kick.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/kick.ts b/src/commands/kick.ts index 72e2574..af1439c 100644 --- a/src/commands/kick.ts +++ b/src/commands/kick.ts @@ -1,4 +1,3 @@ -import moment, { unitOfTime } from 'moment'; import { Message, User } from 'eris'; import { Client, Command } from '../class';