Merge branch 'dev'

merge-requests/13/head
Matthew 2020-06-16 17:32:25 -04:00
commit 24246ccddc
No known key found for this signature in database
GPG Key ID: F841AB9BF496C194
4 changed files with 36 additions and 42 deletions

View File

@ -28,7 +28,7 @@ export default class Client extends eris.Client {
} }
public async loadDatabase() { public async loadDatabase() {
await mongoose.connect(this.config.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true }); await mongoose.connect(this.config.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true, poolSize: 50 });
} }
public loadPlugins() { public loadPlugins() {

View File

@ -47,7 +47,7 @@ export default class Whois extends Command {
if (ackResolve?.emailAddress) { if (ackResolve?.emailAddress) {
description += `${emotes.email} ${ackResolve.emailAddress}\n`; description += `${emotes.email} ${ackResolve.emailAddress}\n`;
} }
const pager = await this.client.db.PagerNumber.findOne({ individualAssignID: member.user.id }); const pager = await this.client.db.PagerNumber.findOne({ individualAssignID: member.user.id }).lean().exec();
if (pager?.num) { if (pager?.num) {
description += `📡 ${pager.num}\n`; description += `📡 ${pager.num}\n`;
} }
@ -90,7 +90,7 @@ export default class Whois extends Command {
if (bit & 1073741824) permissions.push('Manage Emojis'); if (bit & 1073741824) permissions.push('Manage Emojis');
if (bit & 4) permissions.push('Ban Members'); if (bit & 4) permissions.push('Ban Members');
if (bit & 2) permissions.push('Kick Members'); if (bit & 2) permissions.push('Kick Members');
const account = await this.client.db.Member.findOne({ userID: member.id }); const account = await this.client.db.Member.findOne({ userID: member.id }).lean().exec();
if (account?.additional?.langs.length > 0) { if (account?.additional?.langs.length > 0) {
const langs: string[] = []; const langs: string[] = [];
for (const lang of account.additional.langs.sort((a, b) => a.localeCompare(b))) { for (const lang of account.additional.langs.sort((a, b) => a.localeCompare(b))) {

View File

@ -1,16 +1,15 @@
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
import { Client } from '../class'; import { Client } from '../class';
import { PagerNumberInterface } from '../models';
let interval: NodeJS.Timeout; let interval: NodeJS.Timeout;
async function setupDepartmentCodes(client: Client): Promise<void> { async function setupDepartmentCodes(client: Client): Promise<void> {
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' }); const directorPagers = await client.db.PagerNumber.findOne({ num: '00' }).lean().exec();
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' }); const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' }).lean().exec();
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' }); const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' }).lean().exec();
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' }); const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' }).lean().exec();
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' }); const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' }).lean().exec();
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' }); const associatePagers = await client.db.PagerNumber.findOne({ num: '22' }).lean().exec();
if (!directorPagers) { if (!directorPagers) {
const setup = new client.db.PagerNumber({ const setup = new client.db.PagerNumber({
@ -80,8 +79,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
// const takenPagers = new Set<string>(); // const takenPagers = new Set<string>();
members.forEach(async (member) => { for (const member of members.values()) {
let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }); 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')) {
let randomPagerNumber: string; let randomPagerNumber: string;
@ -106,9 +105,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
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}.`);
}); });
} } else if (!pager && member.roles.includes('701454855952138300')) {
// Supervisors // Supervisors
if (!pager && member.roles.includes('701454855952138300')) {
let randomPagerNumber: string; let randomPagerNumber: string;
let status = true; let status = true;
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
@ -130,9 +128,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
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}.`);
}); });
} } else if (!pager && member.roles.includes('701454780828221450')) {
// Technicians // Technicians
if (!pager && member.roles.includes('701454780828221450')) {
let randomPagerNumber: string; let randomPagerNumber: string;
let status = true; let status = true;
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
@ -155,9 +152,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
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}.`);
}); });
} } else if (!pager && member.roles.includes('455972169449734144')) {
// Moderators // Moderators
if (!pager && member.roles.includes('455972169449734144')) {
let randomPagerNumber: string; let randomPagerNumber: string;
let status = true; let status = true;
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
@ -180,9 +176,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
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}.`);
}); });
} } else if (!pager && member.roles.includes('453689940140883988')) {
// Core Team // Core Team
if (!pager && member.roles.includes('453689940140883988')) {
let randomPagerNumber: string; let randomPagerNumber: string;
let status = true; let status = true;
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
@ -205,9 +200,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
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}.`);
}); });
} } else if (!pager && member.roles.includes('701481967149121627')) {
// Associates // Associates
if (!pager && member.roles.includes('701481967149121627')) {
let randomPagerNumber: string; let randomPagerNumber: string;
let status = true; let status = true;
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
@ -231,11 +225,11 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
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}.`);
}); });
} }
}); }
// Associates // Associates
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' }); const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
members.forEach(async (member) => { for (const member of members.values()) {
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);
@ -246,10 +240,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (acknowledgement?.emailAddress) await associatePagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } }); if (acknowledgement?.emailAddress) await associatePagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
} }
}); }
// Core Team // Core Team
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' }); const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
members.forEach(async (member) => { for (const member of members.values()) {
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);
@ -260,10 +254,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (acknowledgement?.emailAddress) await coreTeamPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } }); if (acknowledgement?.emailAddress) await coreTeamPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
} }
}); }
// Moderator // Moderator
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' }); const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
members.forEach(async (member) => { for (const member of members.values()) {
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);
@ -274,10 +268,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (acknowledgement?.emailAddress) await moderatorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } }); if (acknowledgement?.emailAddress) await moderatorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
} }
}); }
// Technician // Technician
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' }); const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
members.forEach(async (member) => { for (const member of members.values()) {
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);
@ -288,10 +282,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (acknowledgement?.emailAddress) await technicianPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } }); if (acknowledgement?.emailAddress) await technicianPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
} }
}); }
// Supervisor // Supervisor
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' }); const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
members.forEach(async (member) => { for (const member of members.values()) {
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);
@ -302,10 +296,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (acknowledgement?.emailAddress) await supervisorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } }); if (acknowledgement?.emailAddress) await supervisorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
} }
}); }
// Board of Directors // Board of Directors
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' }); const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
members.forEach(async (member) => { for (const member of members.values()) {
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);
@ -316,7 +310,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
const acknowledgement = resolveStaffInformation(member.id); const acknowledgement = resolveStaffInformation(member.id);
if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } }); if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
} }
}); }
}, 10000); }, 1200000);
return interval; return interval;
} }

View File

@ -5,7 +5,7 @@ let interval: NodeJS.Timeout;
export default async function fetchMembers(client: Client): Promise<NodeJS.Timeout> { export default async function fetchMembers(client: Client): Promise<NodeJS.Timeout> {
await client.guilds.get(client.config.guildID)?.fetchAllMembers(); await client.guilds.get(client.config.guildID)?.fetchAllMembers();
interval = setInterval(async () => { interval = setInterval(async () => {
await client.guilds.get(client.config.guildID).fetchAllMembers(); // await client.guilds.get(client.config.guildID).fetchAllMembers();
}, 1800000); }, 1800000);
return interval; return interval;
} }