From cdb8b0297f806cb3147b3759b0fd234bffbcc3f9 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Tue, 13 Jul 2021 15:04:42 -0400 Subject: added unmute and unban command --- .../extensions/discord-akairo/BushClientUtil.ts | 63 ++++++++++++++++------ 1 file changed, 48 insertions(+), 15 deletions(-) (limited to 'src/lib/extensions/discord-akairo') diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 6c6d49a..a981d30 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -643,21 +643,7 @@ export class BushClientUtil extends ClientUtil { guild: BushGuildResolvable; modlog: string; }): Promise { - let dbModel: typeof Mute | typeof Ban | typeof PunishmentRole; - switch (options.type) { - case 'mute': - dbModel = Mute; - break; - case 'ban': - dbModel = Ban; - break; - case 'role': - dbModel = PunishmentRole; - break; - default: - throw 'choose a valid punishment entry type'; - } - + const dbModel = this.findPunishmentModel(options.type); const expires = options.duration ? new Date(new Date().getTime() + options.duration) : null; const user = this.client.users.resolveId(options.user); const guild = this.client.guilds.resolveId(options.guild); @@ -669,6 +655,53 @@ export class BushClientUtil extends ClientUtil { }); } + public async removePunishmentEntry(options: { + type: 'mute' | 'ban' | 'role'; + user: BushGuildMemberResolvable; + guild: BushGuildResolvable; + }): Promise { + const dbModel = this.findPunishmentModel(options.type); + const user = this.client.users.resolveId(options.user); + const guild = this.client.guilds.resolveId(options.guild); + + let success = true; + + const entries = await dbModel + .findAll({ + // finding all cases of a certain type incase there were duplicates or something + where: { + user, + guild + } + }) + .catch((e) => { + this.client.console.error('removePunishmentEntry', e?.stack || e); + success = false; + }); + if (entries) { + entries.forEach(async (entry) => { + await entry.destroy().catch((e) => { + this.client.console.error('removePunishmentEntry', e?.stack || e); + }); + success = false; + }); + } + return success; + } + + private findPunishmentModel(type: 'mute' | 'ban' | 'role'): typeof Mute | typeof Ban | typeof PunishmentRole { + switch (type) { + case 'mute': + return Mute; + case 'ban': + return Ban; + case 'role': + return PunishmentRole; + default: + throw 'choose a valid punishment entry type'; + } + } + public humanizeDuration(duration: number): string { return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2 }); } -- cgit