diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-14 13:12:32 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-14 13:12:32 -0400 |
commit | 070b5f326d0647e7b105f99811e4bdc915c8652e (patch) | |
tree | 15c5e3366acb9f6056de83924db6dd9db961061a /src/tasks/unban.ts | |
parent | cdb8b0297f806cb3147b3759b0fd234bffbcc3f9 (diff) | |
download | tanzanite-070b5f326d0647e7b105f99811e4bdc915c8652e.tar.gz tanzanite-070b5f326d0647e7b105f99811e4bdc915c8652e.tar.bz2 tanzanite-070b5f326d0647e7b105f99811e4bdc915c8652e.zip |
revamped role command and some other stuff
Diffstat (limited to 'src/tasks/unban.ts')
-rw-r--r-- | src/tasks/unban.ts | 31 |
1 files changed, 8 insertions, 23 deletions
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<void> { - 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}`); } } |