merge-requests/6/merge
Matthew 2020-06-15 23:01:03 -04:00
parent cdbd835a76
commit 03cd37b5e1
No known key found for this signature in database
GPG Key ID: F841AB9BF496C194
1 changed files with 12 additions and 5 deletions

View File

@ -90,6 +90,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
while (status) { while (status) {
randomPagerNumber = `00${String(Math.floor(Math.random() * 9) + 1)}`; randomPagerNumber = `00${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) status = false;
if (check?.num !== randomPagerNumber) status = false; if (check?.num !== randomPagerNumber) status = false;
} }
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
@ -100,6 +101,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
emailAddresses: [acknowledgement.emailAddress], emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
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}.`);
@ -113,7 +115,7 @@ 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?.num !== randomPagerNumber) status = false; if (!check || (check?.num !== randomPagerNumber)) status = true;
} }
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return; if (!acknowledgement || !acknowledgement.emailAddress) return;
@ -123,6 +125,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
emailAddresses: [acknowledgement.emailAddress], emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
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}.`);
@ -137,7 +140,7 @@ 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?.num !== randomPagerNumber) status = false; if (!check || (check?.num !== randomPagerNumber)) status = true;
} }
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return; if (!acknowledgement || !acknowledgement.emailAddress) return;
@ -147,6 +150,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
emailAddresses: [acknowledgement.emailAddress], emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
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}.`);
@ -161,7 +165,7 @@ 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?.num !== randomPagerNumber) status = false; if (!check || (check?.num !== randomPagerNumber)) status = true;
} }
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return; if (!acknowledgement || !acknowledgement.emailAddress) return;
@ -171,6 +175,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
emailAddresses: [acknowledgement.emailAddress], emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
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}.`);
@ -185,7 +190,7 @@ 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?.num !== randomPagerNumber) status = false; if (!check || (check?.num !== randomPagerNumber)) status = true;
} }
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return; if (!acknowledgement || !acknowledgement.emailAddress) return;
@ -195,6 +200,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
emailAddresses: [acknowledgement.emailAddress], emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
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}.`);
@ -209,7 +215,7 @@ 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?.num !== randomPagerNumber) status = false; if (!check || (check?.num !== randomPagerNumber)) status = true;
} }
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return; if (!acknowledgement || !acknowledgement.emailAddress) return;
@ -219,6 +225,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
emailAddresses: [acknowledgement.emailAddress], emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
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}.`);