From 4b2de2175c3808bcdc43c2e7716ba915e45ae408 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 19 Jul 2020 20:08:55 -0400 Subject: [PATCH] fixes for pagers --- src/events/guildMemberAdd.ts | 44 ++++++++++---------- src/events/ready.ts | 1 + src/intervals/departmentPager.ts | 70 ++++++++++++++------------------ src/intervals/fetchMembers.ts | 2 +- src/main.ts | 1 - 5 files changed, 55 insertions(+), 63 deletions(-) diff --git a/src/events/guildMemberAdd.ts b/src/events/guildMemberAdd.ts index bdd7ea5..13b167c 100644 --- a/src/events/guildMemberAdd.ts +++ b/src/events/guildMemberAdd.ts @@ -1,22 +1,22 @@ -import { Member } from 'eris'; -import { Client, Event } from '../class'; - -export default class GuildMemberAdd extends Event { - public client: Client; - - constructor(client: Client) { - super(client); - this.event = 'guildMemberAdd'; - } - - public async run(_, member: Member) { - try { - const search = await this.client.db.local.muted.get(`muted-${member.user.id}`); - if (search === true) { - member.addRole('478373942638149643'); - } - } catch (err) { - this.client.util.handleError(err); - } - } -} +import { Member } from 'eris'; +import { Client, Event } from '../class'; + +export default class GuildMemberAdd extends Event { + public client: Client; + + constructor(client: Client) { + super(client); + this.event = 'guildMemberAdd'; + } + + public async run(_, member: Member) { + try { + const search = await this.client.db.local.muted.get(`muted-${member.user.id}`); + if (search === true) { + member.addRole('478373942638149643'); + } + } catch (err) { + this.client.util.handleError(err); + } + } +} diff --git a/src/events/ready.ts b/src/events/ready.ts index 10389ae..51cba8b 100644 --- a/src/events/ready.ts +++ b/src/events/ready.ts @@ -9,6 +9,7 @@ export default class Ready extends Event { } public async run() { + await this.client.loadIntervals(); this.client.util.signale.start(`${this.client.user.username} is now ready!\nServers: ${this.client.guilds.size}\nUsers: ${this.client.users.size}\n\nhttps://gitlab.libraryofcode.org/engineering/communityrelations`); this.client.on('error', (err) => { this.client.util.handleError(err); diff --git a/src/intervals/departmentPager.ts b/src/intervals/departmentPager.ts index fed1b38..9093e7d 100644 --- a/src/intervals/departmentPager.ts +++ b/src/intervals/departmentPager.ts @@ -75,18 +75,18 @@ function logNewPager(client: Client, num: string, member: Member): void { channel.createMessage(`__**'${member.user.username}#${member.user.discriminator}' assigned to pager number '${num}'.**__`); } -export default async function departmentPager(client0: Client): Promise { - setupDepartmentCodes(client0); +export default async function departmentPager(client: Client): Promise { + setupDepartmentCodes(client); + // eslint-disable-next-line no-shadow async function start(client: Client) { const acknowledgements = require(`${__dirname}/../configs/acknowledgements.json`); function resolveStaffInformation(id: string) { return acknowledgements.find((m) => m.id === id); } - // await client.guilds.get(client.config.guildID).fetchAllMembers(); - const { members } = client.guilds.get(client.config.guildID); + await client.guilds.get(client.config.guildID).fetchAllMembers(); + const members = client.guilds.get(client.config.guildID).members.values(); - for (let member of members.values()) { - member = await client.guilds.get(client.config.guildID).getRESTMember(member.id); + for (const member of members) { const pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec(); if (!pager) continue; if (pager.num.startsWith('00') && !member.roles.includes('662163685439045632')) { @@ -116,9 +116,7 @@ export default async function departmentPager(client0: Client): Promise(); - - for (let member of members.values()) { - member = await client.guilds.get(client.config.guildID).getRESTMember(member.id); + for (const member of members) { let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec(); // Directors if (!pager && member.roles.includes('662163685439045632')) { @@ -132,14 +130,14 @@ export default async function departmentPager(client0: Client): Promise { @@ -157,14 +155,14 @@ export default async function departmentPager(client0: Client): Promise { @@ -183,14 +181,14 @@ export default async function departmentPager(client0: Client): Promise { @@ -209,14 +207,14 @@ export default async function departmentPager(client0: Client): Promise { @@ -235,14 +233,14 @@ export default async function departmentPager(client0: Client): Promise { @@ -261,14 +259,14 @@ export default async function departmentPager(client0: Client): Promise { @@ -279,8 +277,7 @@ export default async function departmentPager(client0: Client): Promise { - client0.util.signale.time('pagerint'); - await start(client0); - client0.util.signale.timeEnd('pagerint'); + client.util.signale.time('pagerint'); + await start(client); + client.util.signale.timeEnd('pagerint'); }, 300000); return interval; } diff --git a/src/intervals/fetchMembers.ts b/src/intervals/fetchMembers.ts index fcc1862..2cdf29c 100644 --- a/src/intervals/fetchMembers.ts +++ b/src/intervals/fetchMembers.ts @@ -3,7 +3,7 @@ import { Client } from '../class'; let interval: NodeJS.Timeout; export default async function fetchMembers(client: Client): Promise { - await client.guilds.get(client.config.guildID)?.fetchAllMembers(); + // await client.guilds.get(client.config.guildID)?.fetchAllMembers(); interval = setInterval(async () => { // await client.guilds.get(client.config.guildID).fetchAllMembers(); }, 1800000); diff --git a/src/main.ts b/src/main.ts index 55b2802..b061f78 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,7 +15,6 @@ async function main(): Promise { client.config = config; await client.loadDatabase(); client.loadPlugins(); - await client.loadIntervals(); await client.loadEvents(eventFiles); await client.loadCommands(commandFiles); client.connect();