From 070b5f326d0647e7b105f99811e4bdc915c8652e Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 14 Jul 2021 13:12:32 -0400 Subject: revamped role command and some other stuff --- src/tasks/unban.ts | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'src/tasks/unban.ts') diff --git a/src/tasks/unban.ts b/src/tasks/unban.ts index f5d6b53..136e6c2 100644 --- a/src/tasks/unban.ts +++ b/src/tasks/unban.ts @@ -1,6 +1,4 @@ -import { Ban, BushTask } from '@lib'; -import { DiscordAPIError } from 'discord.js'; -import { Op } from 'sequelize'; +import { BushGuild, BushTask } from '@lib'; export default class UnbanTask extends BushTask { public constructor() { @@ -10,32 +8,19 @@ export default class UnbanTask extends BushTask { }); } async exec(): Promise { - const rows = await Ban.findAll({ - where: { - [Op.and]: [ - { - expires: { - [Op.lt]: new Date() // Find all rows with an expiry date before now - } - } - ] - } - }); + const rows = await this.client.util.findExpiredEntries('mute'); this.client.logger.verbose(`UnbanTask`, `Queried bans, found <<${rows.length}>> expired bans.`); + for (const row of rows) { - const guild = this.client.guilds.cache.get(row.guild); + const guild = this.client.guilds.cache.get(row.guild) as BushGuild; if (!guild) { await row.destroy(); continue; } - try { - await guild.members.unban(row.user, `Unbanning user because tempban expired`); - } catch (e) { - if (e instanceof DiscordAPIError) { - // Member not banned, ignore - } else throw e; - } - await row.destroy(); + + const result = await guild.unban({ user: row.user, reason: 'Punishment expired.' }); + if (['success', 'user not banned'].includes(result)) await row.destroy(); + else throw result; this.client.logger.verbose(`UnbanTask`, `Unbanned ${row.user}`); } } -- cgit