fixes for pagers

merge-requests/15/head
Matthew 2020-07-19 20:08:55 -04:00
parent e54c89231a
commit 4b2de2175c
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
5 changed files with 55 additions and 63 deletions

View File

@ -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<boolean>(`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<boolean>(`muted-${member.user.id}`);
if (search === true) {
member.addRole('478373942638149643');
}
} catch (err) {
this.client.util.handleError(err);
}
}
}

View File

@ -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);

View File

@ -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<NodeJS.Timeout> {
setupDepartmentCodes(client0);
export default async function departmentPager(client: Client): Promise<NodeJS.Timeout> {
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<NodeJS.T
}
// const takenPagers = new Set<string>();
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<NodeJS.T
if (check?.num !== randomPagerNumber) status = false;
}
const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return;
if (!acknowledgement || !acknowledgement.emailAddress) continue;
const newNumber = new client.db.PagerNumber({
num: randomPagerNumber,
individualAssignID: member.id,
emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id],
});
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
pager = await newNumber.save();
logNewPager(client, randomPagerNumber, member);
client.getDMChannel(member.id).then((chan) => {
@ -157,14 +155,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
if (check?.num !== randomPagerNumber) status = false;
}
const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return;
if (!acknowledgement || !acknowledgement.emailAddress) continue;
const newNumber = new client.db.PagerNumber({
num: randomPagerNumber,
individualAssignID: member.id,
emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id],
});
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save();
client.getDMChannel(member.id).then((chan) => {
@ -183,14 +181,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
if (check?.num !== randomPagerNumber) status = false;
}
const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return;
if (!acknowledgement || !acknowledgement.emailAddress) continue;
const newNumber = new client.db.PagerNumber({
num: randomPagerNumber,
individualAssignID: member.id,
emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id],
});
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save();
client.getDMChannel(member.id).then((chan) => {
@ -209,14 +207,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
if (check?.num !== randomPagerNumber) status = false;
}
const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return;
if (!acknowledgement || !acknowledgement.emailAddress) continue;
const newNumber = new client.db.PagerNumber({
num: randomPagerNumber,
individualAssignID: member.id,
emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id],
});
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save();
client.getDMChannel(member.id).then((chan) => {
@ -235,14 +233,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
if (check?.num !== randomPagerNumber) status = false;
}
const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return;
if (!acknowledgement || !acknowledgement.emailAddress) continue;
const newNumber = new client.db.PagerNumber({
num: randomPagerNumber,
individualAssignID: member.id,
emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id],
});
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save();
client.getDMChannel(member.id).then((chan) => {
@ -261,14 +259,14 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
if (check?.num !== randomPagerNumber) status = false;
}
const acknowledgement = resolveStaffInformation(member.id);
if (!acknowledgement || !acknowledgement.emailAddress) return;
if (!acknowledgement || !acknowledgement.emailAddress) continue;
const newNumber = new client.db.PagerNumber({
num: randomPagerNumber,
individualAssignID: member.id,
emailAddresses: [acknowledgement.emailAddress],
discordIDs: [member.id],
});
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) return;
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save();
client.getDMChannel(member.id).then((chan) => {
@ -279,8 +277,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
// Associates
const associatePagers = await client.db.PagerNumber.findOne({ num: '22' });
for (let member of members.values()) {
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
for (const member of members) {
if (member.roles.includes('701481967149121627') && !associatePagers.discordIDs.includes(member.id)) {
await associatePagers.updateOne({ $addToSet: { discordIDs: member.id } });
const acknowledgement = resolveStaffInformation(member.id);
@ -294,8 +291,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
}
// Core Team
const coreTeamPagers = await client.db.PagerNumber.findOne({ num: '21' });
for (let member of members.values()) {
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
for (const member of members) {
if (member.roles.includes('453689940140883988') && !coreTeamPagers.discordIDs.includes(member.id)) {
await coreTeamPagers.updateOne({ $addToSet: { discordIDs: member.id } });
const acknowledgement = resolveStaffInformation(member.id);
@ -309,8 +305,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
}
// Moderator
const moderatorPagers = await client.db.PagerNumber.findOne({ num: '20' });
for (let member of members.values()) {
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
for (const member of members) {
if (member.roles.includes('455972169449734144') && !moderatorPagers.discordIDs.includes(member.id)) {
await moderatorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
const acknowledgement = resolveStaffInformation(member.id);
@ -324,8 +319,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
}
// Technician
const technicianPagers = await client.db.PagerNumber.findOne({ num: '10' });
for (let member of members.values()) {
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
for (const member of members) {
if (member.roles.includes('701454780828221450') && !technicianPagers.discordIDs.includes(member.id)) {
await technicianPagers.updateOne({ $addToSet: { discordIDs: member.id } });
const acknowledgement = resolveStaffInformation(member.id);
@ -339,8 +333,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
}
// Supervisor
const supervisorPagers = await client.db.PagerNumber.findOne({ num: '01' });
for (let member of members.values()) {
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
for (const member of members) {
if (member.roles.includes('701454855952138300') && !supervisorPagers.discordIDs.includes(member.id)) {
await supervisorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
const acknowledgement = resolveStaffInformation(member.id);
@ -354,8 +347,7 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
}
// Board of Directors
const directorPagers = await client.db.PagerNumber.findOne({ num: '00' });
for (let member of members.values()) {
member = await client.guilds.get(client.config.guildID).getRESTMember(member.id);
for (const member of members) {
if (member.roles.includes('662163685439045632') && !directorPagers.discordIDs.includes(member.id)) {
await directorPagers.updateOne({ $addToSet: { discordIDs: member.id } });
const acknowledgement = resolveStaffInformation(member.id);
@ -368,13 +360,13 @@ export default async function departmentPager(client0: Client): Promise<NodeJS.T
}
}
}
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');
interval = setInterval(async () => {
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;
}

View File

@ -3,7 +3,7 @@ import { Client } from '../class';
let interval: 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 () => {
// await client.guilds.get(client.config.guildID).fetchAllMembers();
}, 1800000);

View File

@ -15,7 +15,6 @@ async function main(): Promise<void> {
client.config = config;
await client.loadDatabase();
client.loadPlugins();
await client.loadIntervals();
await client.loadEvents(eventFiles);
await client.loadCommands(commandFiles);
client.connect();