merge-requests/15/head
Matthew 2020-07-05 14:42:38 -04:00
parent e1fcb15747
commit e39ebfd140
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
19 changed files with 1185 additions and 1184 deletions

View File

@ -24,8 +24,8 @@ export default class Info extends Command {
embed.addField('Discord Library', `Eris (${erisVersion})`, true); embed.addField('Discord Library', `Eris (${erisVersion})`, true);
embed.addField('HTTP Server Library', `Express (${expressVersion})`, true); embed.addField('HTTP Server Library', `Express (${expressVersion})`, true);
embed.addField('Database Library', `MongoDB w/ Mongoose ODM (${mongooseVersion})`, true); embed.addField('Database Library', `MongoDB w/ Mongoose ODM (${mongooseVersion})`, true);
embed.addField('Repository', 'https://gitlab.libraryofcode.org/engineering/communityrelations | Licensed under GNU Affero General Public License V3', true);
embed.addField('Memory Usage', `${Math.round(process.memoryUsage().rss / 1024 / 1024)} MB / ${Math.round(totalmem() / 1024 / 1024 / 1024)} GB`, true); embed.addField('Memory Usage', `${Math.round(process.memoryUsage().rss / 1024 / 1024)} MB / ${Math.round(totalmem() / 1024 / 1024 / 1024)} GB`, true);
embed.addField('Repository', 'https://loc.sh/crgit | Licensed under GNU Affero General Public License V3', true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp(); embed.setTimestamp();
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });

View File

@ -1,7 +1,7 @@
/* eslint-disable no-case-declarations */ /* eslint-disable no-case-declarations */
/* eslint-disable no-continue */ /* eslint-disable no-continue */
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
import { Message, TextableChannel, Textable } from 'eris'; import { Message, TextableChannel } from 'eris';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
export default class Page extends Command { export default class Page extends Command {
@ -11,7 +11,7 @@ export default class Page extends Command {
super(client); super(client);
this.name = 'page'; this.name = 'page';
this.description = 'Pages the specified emergency number, department number, or individual number with the specified pager code.'; this.description = 'Pages the specified emergency number, department number, or individual number with the specified pager code.';
this.usage = 'page <pager number> <pager code>'; this.usage = 'page <pager number> <pager code> [optional message]';
this.aliases = ['p']; this.aliases = ['p'];
this.permissions = 1; this.permissions = 1;
this.enabled = true; this.enabled = true;
@ -52,7 +52,7 @@ export default class Page extends Command {
message.delete(); message.delete();
const loading = await this.loading(message.channel, 'Paging...'); const loading = await this.loading(message.channel, 'Paging...');
const sender = await this.client.db.PagerNumber.findOne({ individualAssignID: message.author.id }); const sender = await this.client.db.PagerNumber.findOne({ individualAssignID: message.author.id });
const page = await this.page(args[0], sender.num, args[1], message); const page = await this.page(args[0], sender.num, args[1], message, args[2] ? args.slice(2).join(' ') : undefined);
if (page.status === true) { if (page.status === true) {
loading.delete(); loading.delete();
return this.success(message.channel, page.message); return this.success(message.channel, page.message);
@ -64,14 +64,15 @@ export default class Page extends Command {
} }
} }
public logPage(sender: { number: string, user?: string }, recipient: { number: string, user?:string }, type: 'discord' | 'email', code: string): void { public logPage(sender: { number: string, user?: string }, recipient: { number: string, user?: string }, type: 'discord' | 'email', code: string): void {
const chan = <TextableChannel> this.client.guilds.get(this.client.config.guildID).channels.get('722636436716781619'); const chan = <TextableChannel> this.client.guilds.get(this.client.config.guildID).channels.get('722636436716781619');
chan.createMessage(`***[${type.toUpperCase()}] \`${sender.number} (${sender.user ? sender.user : ''})\` sent a page to \`${recipient.number} (${recipient.user ? recipient.user : ''})\` with code \`${code}\`.***`); chan.createMessage(`***[${type.toUpperCase()}] \`${sender.number} (${sender.user ? sender.user : ''})\` sent a page to \`${recipient.number} (${recipient.user ? recipient.user : ''})\` with code \`${code}\`.***`);
this.client.util.signale.log(`PAGE (${type.toUpperCase()})| TO: ${recipient.number}, FROM: ${sender.number}, CODE: ${code}`); this.client.util.signale.log(`PAGE (${type.toUpperCase()})| TO: ${recipient.number}, FROM: ${sender.number}, CODE: ${code}`);
} }
public async page(recipientNumber: string, senderNumber: string, code: string, message: Message, options?: { emergencyNumber: string }): Promise<{status: boolean, message: string}> { public async page(recipientNumber: string, senderNumber: string, code: string, message: Message, txt?: string, options?: { emergencyNumber: string }): Promise<{status: boolean, message: string}> {
try { try {
if (txt?.length >= 140) return { status: false, message: 'Your message must be less than 141 characters.' };
const senderEntry = await this.client.db.PagerNumber.findOne({ num: senderNumber }); const senderEntry = await this.client.db.PagerNumber.findOne({ num: senderNumber });
if (!senderEntry) { if (!senderEntry) {
return { status: false, message: 'You do not have a Pager Number.' }; return { status: false, message: 'You do not have a Pager Number.' };
@ -80,29 +81,29 @@ export default class Page extends Command {
switch (recipientNumber) { switch (recipientNumber) {
case '#0': case '#0':
this.local.departmentNumbers.forEach(async (num) => { this.local.departmentNumbers.forEach(async (num) => {
await this.page(num, senderNumber, code, message, { emergencyNumber: '0' }); await this.page(num, senderNumber, code, message, txt, { emergencyNumber: '0' });
}); });
break; break;
case '#1': case '#1':
await this.page('00', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('00', senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page('01', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('01', senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page('10', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('10', senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page('20', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('20', senderNumber, code, message, txt, { emergencyNumber: '0' });
break; break;
case '#2': case '#2':
const matthew = await this.client.db.PagerNumber.findOne({ individualAssignID: '278620217221971968' }); const matthew = await this.client.db.PagerNumber.findOne({ individualAssignID: '278620217221971968' });
const bsian = await this.client.db.PagerNumber.findOne({ individualAssignID: '253600545972027394' }); const bsian = await this.client.db.PagerNumber.findOne({ individualAssignID: '253600545972027394' });
const nightraven = await this.client.db.PagerNumber.findOne({ individualAssignID: '239261547959025665' }); const nightraven = await this.client.db.PagerNumber.findOne({ individualAssignID: '239261547959025665' });
await this.page(matthew?.num, senderNumber, code, message, { emergencyNumber: '0' }); await this.page(matthew?.num, senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page(bsian?.num, senderNumber, code, message, { emergencyNumber: '0' }); await this.page(bsian?.num, senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page(nightraven?.num, senderNumber, code, message, { emergencyNumber: '0' }); await this.page(nightraven?.num, senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page('10', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('10', senderNumber, code, message, txt, { emergencyNumber: '0' });
break; break;
case '#3': case '#3':
await this.page('00', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('00', senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page('01', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('01', senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page('20', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('20', senderNumber, code, message, txt, { emergencyNumber: '0' });
await this.page('21', senderNumber, code, message, { emergencyNumber: '0' }); await this.page('21', senderNumber, code, message, txt, { emergencyNumber: '0' });
break; break;
default: default:
break; break;
@ -127,7 +128,7 @@ export default class Page extends Command {
} else { } else {
this.logPage({ number: senderNumber, user: `${sender.username}#${sender.discriminator}` }, { number: recipientNumber, user: `${recipient.username}#${recipient.discriminator}` }, 'discord', code); this.logPage({ number: senderNumber, user: `${sender.username}#${sender.discriminator}` }, { number: recipientNumber, user: `${recipient.username}#${recipient.discriminator}` }, 'discord', code);
} }
chan.createMessage(`${options?.emergencyNumber ? `[SEN#${options.emergencyNumber}] ` : ''}__**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)})`); chan.createMessage(`${options?.emergencyNumber ? `[SEN#${options.emergencyNumber}] ` : ''}__**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)})${txt ? `\n**Message:** ${txt}` : ''}`);
} }
for (const email of recipientEntry.emailAddresses) { for (const email of recipientEntry.emailAddresses) {
const recipient = this.client.guilds.get(this.client.config.guildID).members.get(recipientEntry.individualAssignID); const recipient = this.client.guilds.get(this.client.config.guildID).members.get(recipientEntry.individualAssignID);
@ -141,7 +142,7 @@ export default class Page extends Command {
from: '"LOC Paging System" <internal@libraryofcode.org>', from: '"LOC Paging System" <internal@libraryofcode.org>',
to: email, to: email,
subject: `PAGE FROM ${recipientNumber}`, subject: `PAGE FROM ${recipientNumber}`,
html: `<h1>Page</h1>${options?.emergencyNumber ? `<h2>[SEN#${options.emergencyNumber}]` : ''}<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)})`, html: `<h1>Page</h1>${options?.emergencyNumber ? `<h2>[SEN#${options.emergencyNumber}]` : ''}<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)})${txt ? `<br><strong>Message:</strong> ${txt}` : ''}`,
}); });
} }
return { status: true, message: `Page to \`${recipientNumber}\` sent.` }; return { status: true, message: `Page to \`${recipientNumber}\` sent.` };