aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/removePunishmentRole.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-14 13:12:32 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-07-14 13:12:32 -0400
commit070b5f326d0647e7b105f99811e4bdc915c8652e (patch)
tree15c5e3366acb9f6056de83924db6dd9db961061a /src/tasks/removePunishmentRole.ts
parentcdb8b0297f806cb3147b3759b0fd234bffbcc3f9 (diff)
downloadtanzanite-070b5f326d0647e7b105f99811e4bdc915c8652e.tar.gz
tanzanite-070b5f326d0647e7b105f99811e4bdc915c8652e.tar.bz2
tanzanite-070b5f326d0647e7b105f99811e4bdc915c8652e.zip
revamped role command and some other stuff
Diffstat (limited to 'src/tasks/removePunishmentRole.ts')
-rw-r--r--src/tasks/removePunishmentRole.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tasks/removePunishmentRole.ts b/src/tasks/removePunishmentRole.ts
index e69de29..d957238 100644
--- a/src/tasks/removePunishmentRole.ts
+++ b/src/tasks/removePunishmentRole.ts
@@ -0,0 +1,32 @@
+import { BushGuildMember, BushTask } from '@lib';
+
+export default class RemovePunishmentRole extends BushTask {
+ public constructor() {
+ super('removePunishmentRole', {
+ delay: 30_000, // 1/2 min
+ runOnStart: true
+ });
+ }
+ async exec(): Promise<void> {
+ const expiredEntries = await this.client.util.findExpiredEntries('role');
+ this.client.logger.verbose(
+ `RemovePunishmentRoleTask`,
+ `Queried punishment roles, found <<${expiredEntries.length}>> expired punishment roles.`
+ );
+
+ for (const entry of expiredEntries) {
+ const guild = this.client.guilds.cache.get(entry.guild);
+ if (!guild) {
+ await entry.destroy();
+ continue;
+ }
+
+ const member = guild.members.cache.get(entry.user) as BushGuildMember;
+ const result = await member.removePunishRole({ reason: 'Punishment expired.', role: entry.role });
+ if (['success', 'failed to dm'].includes(result)) await entry.destroy();
+ else throw result;
+
+ this.client.logger.verbose(`RemovePunishmentRoleTask`, `Removed a punishment role from ${entry.user}.`);
+ }
+ }
+}