Merge branch 'dev'
commit
6b35619e01
|
@ -5,7 +5,7 @@ import { Message } from 'eris';
|
|||
import { Client, Command, RichEmbed } from '../class';
|
||||
|
||||
export default class Page extends Command {
|
||||
public local: { emergencyNumbers: string[], departmentNumbers: string[], validPagerCodes: string[] };
|
||||
public local: { emergencyNumbers: string[], departmentNumbers: string[], validPagerCodes: string[], codeDict: Map<string, string>, };
|
||||
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
|
@ -20,9 +20,20 @@ export default class Page extends Command {
|
|||
emergencyNumbers: ['#0', '#1', '#2', '#3'],
|
||||
departmentNumbers: ['00', '01', '10', '20', '21', '22'],
|
||||
validPagerCodes: ['911', '811', '210', '265', '411', '419', '555'],
|
||||
codeDict: new Map(),
|
||||
};
|
||||
}
|
||||
|
||||
public init() {
|
||||
this.local.codeDict.set('911', 'Sender is requesting EMERGENCY assistance.');
|
||||
this.local.codeDict.set('811', 'Sender is requesting immediate/ASAP assistance.');
|
||||
this.local.codeDict.set('210', 'Sender is informing you they acknowledged your request, usually sent in response to OK the initial page. (10-4)');
|
||||
this.local.codeDict.set('265', 'Sender is requesting that you check your email.');
|
||||
this.local.codeDict.set('411', 'Sender is requesting information/counsel from you.');
|
||||
this.local.codeDict.set('419', 'Sender didn\'t recognize your request.');
|
||||
this.local.codeDict.set('555', 'Sender is requesting that you contact them.');
|
||||
}
|
||||
|
||||
public async run(message: Message, args: string[]) {
|
||||
try {
|
||||
if (!args[0]) {
|
||||
|
@ -102,7 +113,7 @@ export default class Page extends Command {
|
|||
const sender = this.client.guilds.get(this.client.config.guildID).members.get(senderEntry.individualAssignID);
|
||||
const chan = await this.client.getDMChannel(id);
|
||||
if (!chan) continue;
|
||||
chan.createMessage(`__**Page**__\n**Recipient PN:** ${recipientNumber}\n**Sender PN:** ${senderNumber} (${sender ? `${sender.username}#${sender.discriminator}` : ''})\n**Initial Command:** https://discordapp.com/channels/${message.guild.id}/${message.channel.id}/${message.id} (<#${message.channel.id}>)\n\n**Pager Code:** ${code}`);
|
||||
chan.createMessage(`__**Page**__\n**Recipient PN:** ${recipientNumber}\n**Sender PN:** ${senderNumber} (${sender ? `${sender.username}#${sender.discriminator}` : ''})\n**Initial Command:** https://discordapp.com/channels/${message.guild.id}/${message.channel.id}/${message.id} (<#${message.channel.id}>)\n\n**Pager Code:** ${code} (${this.local.codeDict.get(code)})`);
|
||||
}
|
||||
for (const email of recipientEntry.emailAddresses) {
|
||||
const sender = this.client.guilds.get(this.client.config.guildID).members.get(senderEntry.individualAssignID);
|
||||
|
@ -110,7 +121,7 @@ export default class Page extends Command {
|
|||
from: '"LOC Paging System" <internal@libraryofcode.org>',
|
||||
to: email,
|
||||
subject: `PAGE FROM ${recipientNumber}`,
|
||||
html: `<h1>Page</h1><strong>Recipient PN:</strong> ${recipientNumber}<br><strong>Sender PN:</strong> ${senderNumber} (${sender ? `${sender.username}#${sender.discriminator}` : ''})<br><strong>Initial Command:</strong> https://discordapp.com/channels/${message.guild.id}/${message.channel.id}/${message.id} (<#${message.channel.id}>)<br><br><strong>Pager Code:</strong> ${code}`,
|
||||
html: `<h1>Page</h1><strong>Recipient PN:</strong> ${recipientNumber}<br><strong>Sender PN:</strong> ${senderNumber} (${sender ? `${sender.username}#${sender.discriminator}` : ''})<br><strong>Initial Command:</strong> https://discordapp.com/channels/${message.guild.id}/${message.channel.id}/${message.id} (<#${message.channel.id}>)<br><br><strong>Pager Code:</strong> ${code} (${this.local.codeDict.get(code)})`,
|
||||
});
|
||||
}
|
||||
return { status: true, message: `Page to \`${recipientNumber}\` sent.` };
|
||||
|
|
|
@ -90,6 +90,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
while (status) {
|
||||
randomPagerNumber = `00${String(Math.floor(Math.random() * 9) + 1)}`;
|
||||
const check = await client.db.PagerNumber.findOne({ num: randomPagerNumber });
|
||||
if (check) status = false;
|
||||
if (check?.num !== randomPagerNumber) status = false;
|
||||
}
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -100,6 +101,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
emailAddresses: [acknowledgement.emailAddress],
|
||||
discordIDs: [member.id],
|
||||
});
|
||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||
pager = await newNumber.save();
|
||||
client.getDMChannel(member.id).then((chan) => {
|
||||
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) {
|
||||
randomPagerNumber = `01${String(Math.floor(Math.random() * 9) + 1)}`;
|
||||
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);
|
||||
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
||||
|
@ -123,6 +125,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
emailAddresses: [acknowledgement.emailAddress],
|
||||
discordIDs: [member.id],
|
||||
});
|
||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||
pager = await newNumber.save();
|
||||
client.getDMChannel(member.id).then((chan) => {
|
||||
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)}`;
|
||||
if (randomPagerNumber.length === 3) randomPagerNumber = `${randomPagerNumber}0`;
|
||||
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);
|
||||
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
||||
|
@ -147,6 +150,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
emailAddresses: [acknowledgement.emailAddress],
|
||||
discordIDs: [member.id],
|
||||
});
|
||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||
pager = await newNumber.save();
|
||||
client.getDMChannel(member.id).then((chan) => {
|
||||
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)}`;
|
||||
if (randomPagerNumber.length === 3) randomPagerNumber = `${randomPagerNumber}0`;
|
||||
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);
|
||||
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
||||
|
@ -171,6 +175,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
emailAddresses: [acknowledgement.emailAddress],
|
||||
discordIDs: [member.id],
|
||||
});
|
||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||
pager = await newNumber.save();
|
||||
client.getDMChannel(member.id).then((chan) => {
|
||||
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)}`;
|
||||
if (randomPagerNumber.length === 4) randomPagerNumber = `${randomPagerNumber}0`;
|
||||
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);
|
||||
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
||||
|
@ -195,6 +200,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
emailAddresses: [acknowledgement.emailAddress],
|
||||
discordIDs: [member.id],
|
||||
});
|
||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||
pager = await newNumber.save();
|
||||
client.getDMChannel(member.id).then((chan) => {
|
||||
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)}`;
|
||||
if (randomPagerNumber.length === 4) randomPagerNumber = `${randomPagerNumber}0`;
|
||||
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);
|
||||
if (!acknowledgement || !acknowledgement.emailAddress) return;
|
||||
|
@ -219,6 +225,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
emailAddresses: [acknowledgement.emailAddress],
|
||||
discordIDs: [member.id],
|
||||
});
|
||||
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
|
||||
pager = await newNumber.save();
|
||||
client.getDMChannel(member.id).then((chan) => {
|
||||
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
|
||||
|
|
Loading…
Reference in New Issue