bug fixes for pager number creation
parent
8f52aad3fb
commit
8863004065
|
@ -1,5 +1,6 @@
|
||||||
/* eslint-disable no-continue */
|
/* eslint-disable no-continue */
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
|
import { Member, TextableChannel } from 'eris';
|
||||||
import { Client } from '../class';
|
import { Client } from '../class';
|
||||||
|
|
||||||
let interval: NodeJS.Timeout;
|
let interval: NodeJS.Timeout;
|
||||||
|
@ -68,6 +69,11 @@ async function setupDepartmentCodes(client: Client): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logNewPager(client: Client, num: string, member: Member): void {
|
||||||
|
const channel = <TextableChannel> client.guilds.get(client.config.guildID).channels.get('722636436716781619');
|
||||||
|
channel.createMessage(`__**'${member.user.username}#${member.user.discriminator}' assigned to pager number '${num}'.**__`);
|
||||||
|
}
|
||||||
|
|
||||||
export default function departmentPager(client: Client): NodeJS.Timeout {
|
export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
setupDepartmentCodes(client);
|
setupDepartmentCodes(client);
|
||||||
interval = setInterval(async () => {
|
interval = setInterval(async () => {
|
||||||
|
@ -127,6 +133,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
});
|
});
|
||||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||||
pager = await newNumber.save();
|
pager = await newNumber.save();
|
||||||
|
logNewPager(client, randomPagerNumber, member);
|
||||||
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}.`);
|
||||||
});
|
});
|
||||||
|
@ -138,7 +145,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
while (status) {
|
while (status) {
|
||||||
randomPagerNumber = `01${String(Math.floor(Math.random() * 9) + 1)}`;
|
randomPagerNumber = `01${String(Math.floor(Math.random() * 9) + 1)}`;
|
||||||
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
||||||
if (!check || (check?.num !== randomPagerNumber)) status = true;
|
if (check) 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) return;
|
||||||
|
@ -149,6 +157,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
discordIDs: [member.id],
|
discordIDs: [member.id],
|
||||||
});
|
});
|
||||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||||
|
logNewPager(client, randomPagerNumber, member);
|
||||||
pager = await newNumber.save();
|
pager = await newNumber.save();
|
||||||
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}.`);
|
||||||
|
@ -162,7 +171,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
randomPagerNumber = `10${String(Math.floor(Math.random() * 99) + 1)}`;
|
randomPagerNumber = `10${String(Math.floor(Math.random() * 99) + 1)}`;
|
||||||
if (randomPagerNumber.length === 3) randomPagerNumber = `${randomPagerNumber}0`;
|
if (randomPagerNumber.length === 3) randomPagerNumber = `${randomPagerNumber}0`;
|
||||||
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
||||||
if (!check || (check?.num !== randomPagerNumber)) status = true;
|
if (check) 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) return;
|
||||||
|
@ -173,6 +183,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
discordIDs: [member.id],
|
discordIDs: [member.id],
|
||||||
});
|
});
|
||||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||||
|
logNewPager(client, randomPagerNumber, member);
|
||||||
pager = await newNumber.save();
|
pager = await newNumber.save();
|
||||||
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}.`);
|
||||||
|
@ -186,7 +197,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
randomPagerNumber = `20${String(Math.floor(Math.random() * 99) + 1)}`;
|
randomPagerNumber = `20${String(Math.floor(Math.random() * 99) + 1)}`;
|
||||||
if (randomPagerNumber.length === 3) randomPagerNumber = `${randomPagerNumber}0`;
|
if (randomPagerNumber.length === 3) randomPagerNumber = `${randomPagerNumber}0`;
|
||||||
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
||||||
if (!check || (check?.num !== randomPagerNumber)) status = true;
|
if (check) 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) return;
|
||||||
|
@ -197,6 +209,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
discordIDs: [member.id],
|
discordIDs: [member.id],
|
||||||
});
|
});
|
||||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||||
|
logNewPager(client, randomPagerNumber, member);
|
||||||
pager = await newNumber.save();
|
pager = await newNumber.save();
|
||||||
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}.`);
|
||||||
|
@ -210,7 +223,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
randomPagerNumber = `21${String(Math.floor(Math.random() * 999) + 1)}`;
|
randomPagerNumber = `21${String(Math.floor(Math.random() * 999) + 1)}`;
|
||||||
if (randomPagerNumber.length === 4) randomPagerNumber = `${randomPagerNumber}0`;
|
if (randomPagerNumber.length === 4) randomPagerNumber = `${randomPagerNumber}0`;
|
||||||
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
||||||
if (!check || (check?.num !== randomPagerNumber)) status = true;
|
if (check) 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) return;
|
||||||
|
@ -221,6 +235,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
discordIDs: [member.id],
|
discordIDs: [member.id],
|
||||||
});
|
});
|
||||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||||
|
logNewPager(client, randomPagerNumber, member);
|
||||||
pager = await newNumber.save();
|
pager = await newNumber.save();
|
||||||
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}.`);
|
||||||
|
@ -234,7 +249,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
randomPagerNumber = `22${String(Math.floor(Math.random() * 999) + 1)}`;
|
randomPagerNumber = `22${String(Math.floor(Math.random() * 999) + 1)}`;
|
||||||
if (randomPagerNumber.length === 4) randomPagerNumber = `${randomPagerNumber}0`;
|
if (randomPagerNumber.length === 4) randomPagerNumber = `${randomPagerNumber}0`;
|
||||||
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
||||||
if (!check || (check?.num !== randomPagerNumber)) status = true;
|
if (check) 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) return;
|
||||||
|
@ -245,6 +261,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
discordIDs: [member.id],
|
discordIDs: [member.id],
|
||||||
});
|
});
|
||||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||||
|
logNewPager(client, randomPagerNumber, member);
|
||||||
pager = await newNumber.save();
|
pager = await newNumber.save();
|
||||||
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}.`);
|
||||||
|
@ -336,6 +353,6 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
||||||
if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1200000);
|
}, 300000);
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue