aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/unban.ts
diff options
context:
space:
mode:
authorTymanWasTaken <32660892+tymanwastaken@users.noreply.github.com>2021-05-28 21:54:50 -0600
committerTymanWasTaken <32660892+tymanwastaken@users.noreply.github.com>2021-05-28 21:54:50 -0600
commit2456dab3db0d8eaae515606b83a6c0c317d009b0 (patch)
treec20448112d43c1b4ffae1395584d9b202aeee3ed /src/tasks/unban.ts
parent1e9e334097702c68d871365fc016aa096d03c491 (diff)
parent5b5f0bf5667b922037508dfa88e40a1f8a2671ec (diff)
downloadtanzanite-2456dab3db0d8eaae515606b83a6c0c317d009b0.tar.gz
tanzanite-2456dab3db0d8eaae515606b83a6c0c317d009b0.tar.bz2
tanzanite-2456dab3db0d8eaae515606b83a6c0c317d009b0.zip
fix conflicts
Diffstat (limited to 'src/tasks/unban.ts')
-rw-r--r--src/tasks/unban.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tasks/unban.ts b/src/tasks/unban.ts
new file mode 100644
index 0000000..564a2a3
--- /dev/null
+++ b/src/tasks/unban.ts
@@ -0,0 +1,44 @@
+import chalk from 'chalk';
+import { DiscordAPIError } from 'discord.js';
+import { Op } from 'sequelize';
+import { BushTask } from '../lib/extensions/BushTask';
+import { Ban } from '../lib/models';
+
+export default class UnbanTask extends BushTask {
+ constructor() {
+ super('unban', {
+ delay: 30_000, // 1/2 min
+ runOnStart: true
+ });
+ }
+ 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
+ }
+ }
+ ]
+ }
+ });
+ this.client.logger.verbose(chalk.cyan(`Queried bans, found ${rows.length} expired bans.`));
+ for (const row of rows) {
+ const guild = this.client.guilds.cache.get(row.guild);
+ 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();
+ this.client.logger.verbose(chalk.cyan('Unbanned user'));
+ }
+ }
+}