changes to pager
parent
b255b7fd05
commit
842efb4f46
|
@ -3,7 +3,7 @@ import { createPaginationEmbed } from 'eris-pagination';
|
|||
import { Client, Command, RichEmbed } from '../class';
|
||||
import { members } from '.';
|
||||
|
||||
export default class extends Command {
|
||||
export default class Members extends Command {
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'members';
|
||||
|
|
|
@ -75,17 +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 function departmentPager(client: Client): NodeJS.Timeout {
|
||||
export default async function departmentPager(client: Client): Promise<NodeJS.Timeout> {
|
||||
setupDepartmentCodes(client);
|
||||
interval = setInterval(async () => {
|
||||
async function start() {
|
||||
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();
|
||||
// await client.guilds.get(client.config.guildID).fetchAllMembers();
|
||||
const { members } = client.guilds.get(client.config.guildID);
|
||||
|
||||
for (const member of members.values()) {
|
||||
for (let member of members.values()) {
|
||||
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
||||
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,7 +117,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
|
||||
// const takenPagers = new Set<string>();
|
||||
|
||||
for (const member of members.values()) {
|
||||
for (let member of members.values()) {
|
||||
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
||||
let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec();
|
||||
// Directors
|
||||
if (!pager && member.roles.includes('662163685439045632')) {
|
||||
|
@ -277,7 +279,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
|
||||
// Associates
|
||||
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
|
||||
for (const member of members.values()) {
|
||||
for (let member of members.values()) {
|
||||
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
||||
if (member.roles.includes('701481967149121627') && !associatePagers.discordIDs.includes(member.id)) {
|
||||
await associatePagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -291,7 +294,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
}
|
||||
// Core Team
|
||||
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
|
||||
for (const member of members.values()) {
|
||||
for (let member of members.values()) {
|
||||
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
||||
if (member.roles.includes('453689940140883988') && !coreTeamPagers.discordIDs.includes(member.id)) {
|
||||
await coreTeamPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -305,7 +309,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
}
|
||||
// Moderator
|
||||
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
|
||||
for (const member of members.values()) {
|
||||
for (let member of members.values()) {
|
||||
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
||||
if (member.roles.includes('455972169449734144') && !moderatorPagers.discordIDs.includes(member.id)) {
|
||||
await moderatorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -319,7 +324,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
}
|
||||
// Technician
|
||||
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
|
||||
for (const member of members.values()) {
|
||||
for (let member of members.values()) {
|
||||
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
||||
if (member.roles.includes('701454780828221450') && !technicianPagers.discordIDs.includes(member.id)) {
|
||||
await technicianPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -333,7 +339,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
}
|
||||
// Supervisor
|
||||
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
|
||||
for (const member of members.values()) {
|
||||
for (let member of members.values()) {
|
||||
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
||||
if (member.roles.includes('701454855952138300') && !supervisorPagers.discordIDs.includes(member.id)) {
|
||||
await supervisorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -347,7 +354,8 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
}
|
||||
// Board of Directors
|
||||
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
|
||||
for (const member of members.values()) {
|
||||
for (let member of members.values()) {
|
||||
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
|
||||
if (member.roles.includes('662163685439045632') && !directorPagers.discordIDs.includes(member.id)) {
|
||||
await directorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
|
||||
const acknowledgement = resolveStaffInformation(member.id);
|
||||
|
@ -359,6 +367,14 @@ export default function departmentPager(client: Client): NodeJS.Timeout {
|
|||
if (acknowledgement?.emailAddress) await directorPagers.updateOne({ $pull: { emailAddresses: acknowledgement.emailAddress } });
|
||||
}
|
||||
}
|
||||
}
|
||||
client.util.signale.time('pagerint');
|
||||
await start();
|
||||
client.util.signale.timeEnd('pagerint');
|
||||
interval = setInterval(async () => {
|
||||
client.util.signale.time('pagerint');
|
||||
await start();
|
||||
client.util.signale.timeEnd('pagerint');
|
||||
}, 300000);
|
||||
return interval;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue