From 8f52aad3fbd594de71455bf3a75bc8bd22349b24 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Wed, 17 Jun 2020 19:11:11 -0400 Subject: [PATCH] check for pager role changes --- src/intervals/departmentPager.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/intervals/departmentPager.ts b/src/intervals/departmentPager.ts index a1c82cc..2540811 100644 --- a/src/intervals/departmentPager.ts +++ b/src/intervals/departmentPager.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-continue */ /* eslint-disable no-await-in-loop */ import { Client } from '../class'; @@ -77,6 +78,30 @@ export default function departmentPager(client: Client): NodeJS.Timeout { // await client.guilds.get(client.config.guildID).fetchAllMembers(); const { members } = client.guilds.get(client.config.guildID); + for (const member of members.values()) { + const pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec(); + if (!pager) continue; + if (pager.num.startsWith('00') && !member.roles.includes('662163685439045632')) { + client.db.PagerNumber.deleteOne({ num: pager.num }); + client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); + } else if (pager.num.startsWith('01') && !member.roles.includes('701454855952138300')) { + client.db.PagerNumber.deleteOne({ num: pager.num }); + client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); + } else if (pager.num.startsWith('10') && !member.roles.includes('701454780828221450')) { + client.db.PagerNumber.deleteOne({ num: pager.num }); + client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); + } else if (pager.num.startsWith('20') && !member.roles.includes('455972169449734144')) { + client.db.PagerNumber.deleteOne({ num: pager.num }); + client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); + } else if (pager.num.startsWith('21') && !member.roles.includes('453689940140883988')) { + client.db.PagerNumber.deleteOne({ num: pager.num }); + client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); + } else if (pager.num.startsWith('22') && !member.roles.includes('701481967149121627')) { + client.db.PagerNumber.deleteOne({ num: pager.num }); + client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); + } + } + // const takenPagers = new Set(); for (const member of members.values()) {