|
|
@ -1,16 +1,15 @@
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
import { Client } from '../class';
|
|
|
|
import { Client } from '../class';
|
|
|
|
import { PagerNumberInterface } from '../models';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let interval: NodeJS.Timeout;
|
|
|
|
let interval: NodeJS.Timeout;
|
|
|
|
|
|
|
|
|
|
|
|
async function setupDepartmentCodes(client: Client): Promise<void> {
|
|
|
|
async function setupDepartmentCodes(client: Client): Promise<void> {
|
|
|
|
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
|
|
|
|
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' }).lean().exec();
|
|
|
|
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
|
|
|
|
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' }).lean().exec();
|
|
|
|
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
|
|
|
|
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' }).lean().exec();
|
|
|
|
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
|
|
|
|
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' }).lean().exec();
|
|
|
|
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
|
|
|
|
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' }).lean().exec();
|
|
|
|
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
|
|
|
|
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' }).lean().exec();
|
|
|
|
|
|
|
|
|
|
|
|
if (!directorPagers) {
|
|
|
|
if (!directorPagers) {
|
|
|
|
const setup = new client.db.PagerNumber({
|
|
|
|
const setup = new client.db.PagerNumber({
|
|
|
@ -80,8 +79,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
|
|
|
|
|
|
|
|
// const takenPagers = new Set<string>();
|
|
|
|
// const takenPagers = new Set<string>();
|
|
|
|
|
|
|
|
|
|
|
|
members.forEach(async (member) => {
|
|
|
|
for (const member of members.values()) {
|
|
|
|
let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id });
|
|
|
|
let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec();
|
|
|
|
// Directors
|
|
|
|
// Directors
|
|
|
|
if (!pager && member.roles.includes('662163685439045632')) {
|
|
|
|
if (!pager && member.roles.includes('662163685439045632')) {
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let randomPagerNumber: string;
|
|
|
@ -106,9 +105,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (!pager && member.roles.includes('701454855952138300')) {
|
|
|
|
// Supervisors
|
|
|
|
// Supervisors
|
|
|
|
if (!pager && member.roles.includes('701454855952138300')) {
|
|
|
|
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let status = true;
|
|
|
|
let status = true;
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
@ -130,9 +128,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (!pager && member.roles.includes('701454780828221450')) {
|
|
|
|
// Technicians
|
|
|
|
// Technicians
|
|
|
|
if (!pager && member.roles.includes('701454780828221450')) {
|
|
|
|
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let status = true;
|
|
|
|
let status = true;
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
@ -155,9 +152,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (!pager && member.roles.includes('455972169449734144')) {
|
|
|
|
// Moderators
|
|
|
|
// Moderators
|
|
|
|
if (!pager && member.roles.includes('455972169449734144')) {
|
|
|
|
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let status = true;
|
|
|
|
let status = true;
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
@ -180,9 +176,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (!pager && member.roles.includes('453689940140883988')) {
|
|
|
|
// Core Team
|
|
|
|
// Core Team
|
|
|
|
if (!pager && member.roles.includes('453689940140883988')) {
|
|
|
|
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let status = true;
|
|
|
|
let status = true;
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
@ -205,9 +200,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if (!pager && member.roles.includes('701481967149121627')) {
|
|
|
|
// Associates
|
|
|
|
// Associates
|
|
|
|
if (!pager && member.roles.includes('701481967149121627')) {
|
|
|
|
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let randomPagerNumber: string;
|
|
|
|
let status = true;
|
|
|
|
let status = true;
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
@ -231,11 +225,11 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Associates
|
|
|
|
// Associates
|
|
|
|
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
|
|
|
|
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
|
|
|
|
members.forEach(async (member) => {
|
|
|
|
for (const member of members.values()) {
|
|
|
|
if (member.roles.includes('701481967149121627') && !associatePagers.discordIDs.includes(member.id)) {
|
|
|
|
if (member.roles.includes('701481967149121627') && !associatePagers.discordIDs.includes(member.id)) {
|
|
|
|
await associatePagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
await associatePagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
@ -246,10 +240,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (acknowledgement?.emailAddress) await associatePagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
if (acknowledgement?.emailAddress) await associatePagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Core Team
|
|
|
|
// Core Team
|
|
|
|
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
|
|
|
|
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
|
|
|
|
members.forEach(async (member) => {
|
|
|
|
for (const member of members.values()) {
|
|
|
|
if (member.roles.includes('453689940140883988') && !coreTeamPagers.discordIDs.includes(member.id)) {
|
|
|
|
if (member.roles.includes('453689940140883988') && !coreTeamPagers.discordIDs.includes(member.id)) {
|
|
|
|
await coreTeamPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
await coreTeamPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
@ -260,10 +254,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (acknowledgement?.emailAddress) await coreTeamPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
if (acknowledgement?.emailAddress) await coreTeamPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Moderator
|
|
|
|
// Moderator
|
|
|
|
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
|
|
|
|
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
|
|
|
|
members.forEach(async (member) => {
|
|
|
|
for (const member of members.values()) {
|
|
|
|
if (member.roles.includes('455972169449734144') && !moderatorPagers.discordIDs.includes(member.id)) {
|
|
|
|
if (member.roles.includes('455972169449734144') && !moderatorPagers.discordIDs.includes(member.id)) {
|
|
|
|
await moderatorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
await moderatorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
@ -274,10 +268,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (acknowledgement?.emailAddress) await moderatorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
if (acknowledgement?.emailAddress) await moderatorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Technician
|
|
|
|
// Technician
|
|
|
|
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
|
|
|
|
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
|
|
|
|
members.forEach(async (member) => {
|
|
|
|
for (const member of members.values()) {
|
|
|
|
if (member.roles.includes('701454780828221450') && !technicianPagers.discordIDs.includes(member.id)) {
|
|
|
|
if (member.roles.includes('701454780828221450') && !technicianPagers.discordIDs.includes(member.id)) {
|
|
|
|
await technicianPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
await technicianPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
@ -288,10 +282,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (acknowledgement?.emailAddress) await technicianPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
if (acknowledgement?.emailAddress) await technicianPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Supervisor
|
|
|
|
// Supervisor
|
|
|
|
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
|
|
|
|
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
|
|
|
|
members.forEach(async (member) => {
|
|
|
|
for (const member of members.values()) {
|
|
|
|
if (member.roles.includes('701454855952138300') && !supervisorPagers.discordIDs.includes(member.id)) {
|
|
|
|
if (member.roles.includes('701454855952138300') && !supervisorPagers.discordIDs.includes(member.id)) {
|
|
|
|
await supervisorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
await supervisorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
@ -302,10 +296,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (acknowledgement?.emailAddress) await supervisorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
if (acknowledgement?.emailAddress) await supervisorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Board of Directors
|
|
|
|
// Board of Directors
|
|
|
|
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
|
|
|
|
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
|
|
|
|
members.forEach(async (member) => {
|
|
|
|
for (const member of members.values()) {
|
|
|
|
if (member.roles.includes('662163685439045632') && !directorPagers.discordIDs.includes(member.id)) {
|
|
|
|
if (member.roles.includes('662163685439045632') && !directorPagers.discordIDs.includes(member.id)) {
|
|
|
|
await directorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
await directorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
@ -316,7 +310,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 10000);
|
|
|
|
}, 1200000);
|
|
|
|
return interval;
|
|
|
|
return interval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|