|
|
@ -75,18 +75,18 @@ function logNewPager(client: Client, num: string, member: Member): void {
|
|
|
|
channel.createMessage(`__**'${member.user.username}#${member.user.discriminator}' assigned to pager number '${num}'.**__`);
|
|
|
|
channel.createMessage(`__**'${member.user.username}#${member.user.discriminator}' assigned to pager number '${num}'.**__`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default async function departmentPager(client0: Client): Promise<NodeJS.Timeout> {
|
|
|
|
export default async function departmentPager(client: Client): Promise<NodeJS.Timeout> {
|
|
|
|
setupDepartmentCodes(client0);
|
|
|
|
setupDepartmentCodes(client);
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-shadow
|
|
|
|
async function start(client: Client) {
|
|
|
|
async function start(client: Client) {
|
|
|
|
const acknowledgements = require(`${__dirname}/../configs/acknowledgements.json`);
|
|
|
|
const acknowledgements = require(`${__dirname}/../configs/acknowledgements.json`);
|
|
|
|
function resolveStaffInformation(id: string) {
|
|
|
|
function resolveStaffInformation(id: string) {
|
|
|
|
return acknowledgements.find((m) => m.id === id);
|
|
|
|
return acknowledgements.find((m) => m.id === id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// await client.guilds.get(client.config.guildID).fetchAllMembers();
|
|
|
|
await client.guilds.get(client.config.guildID).fetchAllMembers();
|
|
|
|
const { members } = client.guilds.get(client.config.guildID);
|
|
|
|
const members = client.guilds.get(client.config.guildID).members.values();
|
|
|
|
|
|
|
|
|
|
|
|
for (let member of members.values()) {
|
|
|
|
for (const member of members) {
|
|
|
|
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
|
|
|
|
|
|
|
const pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec();
|
|
|
|
const pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec();
|
|
|
|
if (!pager) continue;
|
|
|
|
if (!pager) continue;
|
|
|
|
if (pager.num.startsWith('00') && !member.roles.includes('662163685439045632')) {
|
|
|
|
if (pager.num.startsWith('00') && !member.roles.includes('662163685439045632')) {
|
|
|
@ -116,9 +116,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// const takenPagers = new Set<string>();
|
|
|
|
// const takenPagers = new Set<string>();
|
|
|
|
|
|
|
|
for (const member of members) {
|
|
|
|
for (let member of members.values()) {
|
|
|
|
|
|
|
|
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
|
|
|
|
|
|
|
let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec();
|
|
|
|
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')) {
|
|
|
@ -132,14 +130,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) continue;
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
num: randomPagerNumber,
|
|
|
|
num: randomPagerNumber,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
|
|
|
|
pager = await newNumber.save();
|
|
|
|
pager = await newNumber.save();
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
@ -157,14 +155,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) continue;
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
num: randomPagerNumber,
|
|
|
|
num: randomPagerNumber,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
pager = await newNumber.save();
|
|
|
|
pager = await newNumber.save();
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
@ -183,14 +181,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) continue;
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
num: randomPagerNumber,
|
|
|
|
num: randomPagerNumber,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
pager = await newNumber.save();
|
|
|
|
pager = await newNumber.save();
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
@ -209,14 +207,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) continue;
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
num: randomPagerNumber,
|
|
|
|
num: randomPagerNumber,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
pager = await newNumber.save();
|
|
|
|
pager = await newNumber.save();
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
@ -235,14 +233,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) continue;
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
num: randomPagerNumber,
|
|
|
|
num: randomPagerNumber,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
pager = await newNumber.save();
|
|
|
|
pager = await newNumber.save();
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
@ -261,14 +259,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
if (check?.num !== randomPagerNumber) status = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
const acknowledgement = resolveStaffInformation(member.id);
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
|
|
|
if (!acknowledgement || !acknowledgement.emailAddress) continue;
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
const newNumber = new client.db.PagerNumber({
|
|
|
|
num: randomPagerNumber,
|
|
|
|
num: randomPagerNumber,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
individualAssignID: member.id,
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
emailAddresses: [acknowledgement.emailAddress],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
discordIDs: [member.id],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
|
|
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
logNewPager(client, randomPagerNumber, member);
|
|
|
|
pager = await newNumber.save();
|
|
|
|
pager = await newNumber.save();
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
|
client.getDMChannel(member.id).then((chan) => {
|
|
|
@ -279,8 +277,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
|
|
|
|
|
|
|
|
// Associates
|
|
|
|
// Associates
|
|
|
|
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
|
|
|
|
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
|
|
|
|
for (let member of members.values()) {
|
|
|
|
for (const member of members) {
|
|
|
|
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
|
|
|
|
|
|
|
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);
|
|
|
@ -294,8 +291,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Core Team
|
|
|
|
// Core Team
|
|
|
|
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
|
|
|
|
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
|
|
|
|
for (let member of members.values()) {
|
|
|
|
for (const member of members) {
|
|
|
|
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
|
|
|
|
|
|
|
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);
|
|
|
@ -309,8 +305,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Moderator
|
|
|
|
// Moderator
|
|
|
|
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
|
|
|
|
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
|
|
|
|
for (let member of members.values()) {
|
|
|
|
for (const member of members) {
|
|
|
|
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
|
|
|
|
|
|
|
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);
|
|
|
@ -324,8 +319,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Technician
|
|
|
|
// Technician
|
|
|
|
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
|
|
|
|
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
|
|
|
|
for (let member of members.values()) {
|
|
|
|
for (const member of members) {
|
|
|
|
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
|
|
|
|
|
|
|
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);
|
|
|
@ -339,8 +333,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Supervisor
|
|
|
|
// Supervisor
|
|
|
|
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
|
|
|
|
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
|
|
|
|
for (let member of members.values()) {
|
|
|
|
for (const member of members) {
|
|
|
|
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
|
|
|
|
|
|
|
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);
|
|
|
@ -354,8 +347,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Board of Directors
|
|
|
|
// Board of Directors
|
|
|
|
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
|
|
|
|
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
|
|
|
|
for (let member of members.values()) {
|
|
|
|
for (const member of members) {
|
|
|
|
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
|
|
|
|
|
|
|
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);
|
|
|
@ -368,13 +360,13 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client0.util.signale.time('pagerint');
|
|
|
|
client.util.signale.time('pagerint');
|
|
|
|
await start(client0);
|
|
|
|
await start(client);
|
|
|
|
client0.util.signale.timeEnd('pagerint');
|
|
|
|
client.util.signale.timeEnd('pagerint');
|
|
|
|
interval = setInterval(async () => {
|
|
|
|
interval = setInterval(async () => {
|
|
|
|
client0.util.signale.time('pagerint');
|
|
|
|
client.util.signale.time('pagerint');
|
|
|
|
await start(client0);
|
|
|
|
await start(client);
|
|
|
|
client0.util.signale.timeEnd('pagerint');
|
|
|
|
client.util.signale.timeEnd('pagerint');
|
|
|
|
}, 300000);
|
|
|
|
}, 300000);
|
|
|
|
return interval;
|
|
|
|
return interval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|