fixes to try to fix memory leak
parent
36bc71d272
commit
6522eadf19
|
@ -28,7 +28,7 @@ export default class Client extends eris.Client {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
/* eslint-disable no-await-in-loop */
|
||||
import { Client } from '../class';
|
||||
import { PagerNumberInterface } from '../models';
|
||||
|
||||
let interval: NodeJS.Timeout;
|
||||
|
||||
async function setupDepartmentCodes(client: Client): Promise<void> {
|
||||
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
|
||||
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
|
||||
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
|
||||
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
|
||||
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
|
||||
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
|
||||
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' }).lean().exec();
|
||||
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' }).lean().exec();
|
||||
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' }).lean().exec();
|
||||
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' }).lean().exec();
|
||||
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' }).lean().exec();
|
||||
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' }).lean().exec();
|
||||
|
||||
if (!directorPagers) {
|
||||
const setup = new client.db.PagerNumber({
|
||||
|
@ -80,8 +79,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
|
||||
// const takenPagers = new Set<string>();
|
||||
|
||||
members.forEach(async (member) => {
|
||||
let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id });
|
||||
for (const member of members.values()) {
|
||||
let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec();
|
||||
// Directors
|
||||
if (!pager && member.roles.includes('662163685439045632')) {
|
||||
let randomPagerNumber: string;
|
||||
|
@ -106,9 +105,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
client.getDMChannel(member.id).then((chan) => {
|
||||
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
|
||||
if (!pager && member.roles.includes('701454855952138300')) {
|
||||
let randomPagerNumber: string;
|
||||
let status = true;
|
||||
// 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) => {
|
||||
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
|
||||
if (!pager && member.roles.includes('701454780828221450')) {
|
||||
let randomPagerNumber: string;
|
||||
let status = true;
|
||||
// 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) => {
|
||||
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
|
||||
if (!pager && member.roles.includes('455972169449734144')) {
|
||||
let randomPagerNumber: string;
|
||||
let status = true;
|
||||
// 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) => {
|
||||
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
|
||||
if (!pager && member.roles.includes('453689940140883988')) {
|
||||
let randomPagerNumber: string;
|
||||
let status = true;
|
||||
// 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) => {
|
||||
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
|
||||
if (!pager && member.roles.includes('701481967149121627')) {
|
||||
let randomPagerNumber: string;
|
||||
let status = true;
|
||||
// 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}.`);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Associates
|
||||
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)) {
|
||||
await associatePagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -246,10 +240,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
if (acknowledgement?.emailAddress) await associatePagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
||||
}
|
||||
});
|
||||
}
|
||||
// Core Team
|
||||
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)) {
|
||||
await coreTeamPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -260,10 +254,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
if (acknowledgement?.emailAddress) await coreTeamPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
||||
}
|
||||
});
|
||||
}
|
||||
// Moderator
|
||||
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)) {
|
||||
await moderatorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -274,10 +268,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
if (acknowledgement?.emailAddress) await moderatorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
||||
}
|
||||
});
|
||||
}
|
||||
// Technician
|
||||
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)) {
|
||||
await technicianPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -288,10 +282,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
if (acknowledgement?.emailAddress) await technicianPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
||||
}
|
||||
});
|
||||
}
|
||||
// Supervisor
|
||||
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)) {
|
||||
await supervisorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -302,10 +296,10 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
if (acknowledgement?.emailAddress) await supervisorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
||||
}
|
||||
});
|
||||
}
|
||||
// Board of Directors
|
||||
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)) {
|
||||
await directorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -316,7 +310,7 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
||||
}
|
||||
});
|
||||
}, 10000);
|
||||
}
|
||||
}, 1200000);
|
||||
return interval;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ let interval: NodeJS.Timeout;
|
|||
export default async function fetchMembers(client: Client): Promise<NodeJS.Timeout> {
|
||||
await client.guilds.get(client.config.guildID)?.fetchAllMembers();
|
||||
interval = setInterval(async () => {
|
||||
await client.guilds.get(client.config.guildID).fetchAllMembers();
|
||||
// await client.guilds.get(client.config.guildID).fetchAllMembers();
|
||||
}, 1800000);
|
||||
return interval;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue