aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/unban.ts
blob: 136e6c2277fd4f8aa1b1f8e93e92dc3ce64fcdc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { BushGuild, BushTask } from '@lib';

export default class UnbanTask extends BushTask {
	public constructor() {
		super('unban', {
			delay: 30_000, // 1/2 min
			runOnStart: true
		});
	}
	async exec(): Promise<void> {
		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) as BushGuild;
			if (!guild) {
				await row.destroy();
				continue;
			}

			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}`);
		}
	}
}