auto-conf for adding/removal of members to ALL-STAFF maling list

merge-requests/25/merge
Matthew 2021-03-28 23:24:56 -04:00
parent f9ae2136b0
commit 213aa0b475
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
3 changed files with 39 additions and 15 deletions

View File

@ -1,4 +1,5 @@
/* eslint-disable no-bitwise */ /* eslint-disable no-bitwise */
import axios from 'axios';
import nodemailer from 'nodemailer'; import nodemailer from 'nodemailer';
import childProcess from 'child_process'; import childProcess from 'child_process';
import { promisify } from 'util'; import { promisify } from 'util';
@ -46,6 +47,32 @@ export default class Util {
}; };
} }
public async addUserToMailingList(email: string, list: string) {
try {
const { data } = await axios({
method: 'POST',
url: `localhost:2161/list/${list}/`,
params: { auth: this.client.config.internalKey, email },
});
return true;
} catch {
return false;
}
}
public async removeUserFromMailingList(email: string, list: string) {
try {
const { data } = await axios({
method: 'DELETE',
url: `localhost:2161/list/${list}/`,
params: { auth: this.client.config.internalKey, email },
});
return true;
} catch {
return false;
}
}
public hrn(number: any, fixed: number, formatter: any | any[]) { public hrn(number: any, fixed: number, formatter: any | any[]) {
const builtInFormatters = { const builtInFormatters = {
en: ['KMGTPEZY'.split(''), 1e3], en: ['KMGTPEZY'.split(''), 1e3],

View File

@ -91,31 +91,43 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
if (pager.num.startsWith('00') && !member.roles.includes('662163685439045632')) { if (pager.num.startsWith('00') && !member.roles.includes('662163685439045632')) {
await client.db.PagerNumber.deleteOne({ num: pager.num }); await client.db.PagerNumber.deleteOne({ num: pager.num });
client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`);
await client.util.removeUserFromMailingList(pager.emailAddresses[0], 'all-staff');
} }
if (pager.num.startsWith('01') && !member.roles.includes('701454855952138300')) { if (pager.num.startsWith('01') && !member.roles.includes('701454855952138300')) {
await client.db.PagerNumber.deleteOne({ num: pager.num }); await client.db.PagerNumber.deleteOne({ num: pager.num });
client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`);
await client.util.removeUserFromMailingList(pager.emailAddresses[0], 'all-staff');
} }
if (pager.num.startsWith('10') && !member.roles.includes('701454780828221450')) { if (pager.num.startsWith('10') && !member.roles.includes('701454780828221450')) {
await client.db.PagerNumber.deleteOne({ num: pager.num }); await client.db.PagerNumber.deleteOne({ num: pager.num });
client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`);
await client.util.removeUserFromMailingList(pager.emailAddresses[0], 'all-staff');
} }
if (pager.num.startsWith('20') && !member.roles.includes('455972169449734144')) { if (pager.num.startsWith('20') && !member.roles.includes('455972169449734144')) {
await client.db.PagerNumber.deleteOne({ num: pager.num }); await client.db.PagerNumber.deleteOne({ num: pager.num });
client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`);
await client.util.removeUserFromMailingList(pager.emailAddresses[0], 'all-staff');
} }
if (pager.num.startsWith('21') && !member.roles.includes('453689940140883988')) { if (pager.num.startsWith('21') && !member.roles.includes('453689940140883988')) {
await client.db.PagerNumber.deleteOne({ num: pager.num }); await client.db.PagerNumber.deleteOne({ num: pager.num });
client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`);
await client.util.removeUserFromMailingList(pager.emailAddresses[0], 'all-staff');
} }
if (pager.num.startsWith('22') && !member.roles.includes('701481967149121627')) { if (pager.num.startsWith('22') && !member.roles.includes('701481967149121627')) {
await client.db.PagerNumber.deleteOne({ num: pager.num }); await client.db.PagerNumber.deleteOne({ num: pager.num });
client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`); client.util.signale.log(`Pager Number '${pager.num}' has been deleted.`);
await client.util.removeUserFromMailingList(pager.emailAddresses[0], 'all-staff');
} }
} }
for (const member of members) { for (const member of members) {
let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec(); let pager = await client.db.PagerNumber.findOne({ individualAssignID: member.id }).lean().exec();
// ADD TO ALL STAFF MAILING LIST
if ((member.roles.includes('453689940140883988') || member.roles.includes('701481967149121627')) && !pager) {
const acknowledgement = await resolveStaffInformation(member.id);
await client.util.addUserToMailingList(acknowledgement.emailAddress, 'all-staff');
}
// Directors // Directors
if (!pager && member.roles.includes('662163685439045632')) { if (!pager && member.roles.includes('662163685439045632')) {
let randomPagerNumber: string; let randomPagerNumber: string;

View File

@ -63,14 +63,8 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
staff: boolean, staff: boolean,
locked: boolean, locked: boolean,
notify: boolean, notify: boolean,
// inquiries: [{ name: string, reason: string, date: Date }?],
// softInquiries: [{name: string, date: Date }?]
lastUpdated: Date, lastUpdated: Date,
pin: number[], pin: number[],
/* generalMessagesRatio: number,
supportMessagesRatio: number,
totalModerations: number,
notes: number, */
} = { } = {
userID: member.user.id, userID: member.user.id,
total: 0, total: 0,
@ -82,8 +76,6 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
staff: false, staff: false,
locked: false, locked: false,
notify: false, notify: false,
// inquiries: [],
// softInquiries: [],
lastUpdated: new Date(), lastUpdated: new Date(),
pin: [client.util.randomNumber(100, 999), client.util.randomNumber(10, 99), client.util.randomNumber(1000, 9999)], pin: [client.util.randomNumber(100, 999), client.util.randomNumber(10, 99), client.util.randomNumber(1000, 9999)],
}; };
@ -184,14 +176,7 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
total = Math.floor(((total + activity + roles + moderation + cloudServices + staff + other) * 5.13) * 1.87); total = Math.floor(((total + activity + roles + moderation + cloudServices + staff + other) * 5.13) * 1.87);
/* await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, other, staff, lastUpdate: new Date() } });
if (!score.pin || score.pin?.length < 1) {
await client.db.Score.updateOne({ userID: member.id }, { $set: { pin: [client.util.randomNumber(100, 999), client.util.randomNumber(10, 99), client.util.randomNumber(1000, 9999)] } });
}
*/
client.queue.updateScore(score, total, activity, roles, moderation, cloudServices, other, staff); client.queue.updateScore(score, total, activity, roles, moderation, cloudServices, other, staff);
// client.util.signale.debug(`SCORE SET - ${member.username}\nTotal: ${total}\nActivity: ${activity}\nRoles: ${roles}\nModeration: ${moderation}\nCloud Services: ${cloudServices}\nStaff: ${staff}`);
} }
}; };
await start(); await start();