aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord-akairo
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-13 15:04:42 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-13 15:04:42 -0400
commitcdb8b0297f806cb3147b3759b0fd234bffbcc3f9 (patch)
tree665c8d746e1ec7dee5755edbc7a8e6be7f77c26d /src/lib/extensions/discord-akairo
parent528a4c2bde37ca7d1ded38af31f4a482d492d894 (diff)
downloadtanzanite-cdb8b0297f806cb3147b3759b0fd234bffbcc3f9.tar.gz
tanzanite-cdb8b0297f806cb3147b3759b0fd234bffbcc3f9.tar.bz2
tanzanite-cdb8b0297f806cb3147b3759b0fd234bffbcc3f9.zip
added unmute and unban command
Diffstat (limited to 'src/lib/extensions/discord-akairo')
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts63
1 files changed, 48 insertions, 15 deletions
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<Mute | Ban | PunishmentRole> {
- 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<boolean> {
+ 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 });
}