auto-conf for adding/removal of members to ALL-STAFF maling list
parent
f9ae2136b0
commit
213aa0b475
|
@ -1,4 +1,5 @@
|
|||
/* eslint-disable no-bitwise */
|
||||
import axios from 'axios';
|
||||
import nodemailer from 'nodemailer';
|
||||
import childProcess from 'child_process';
|
||||
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[]) {
|
||||
const builtInFormatters = {
|
||||
en: ['KMGTPEZY'.split(''), 1e3],
|
||||
|
|
|
@ -91,31 +91,43 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
|
|||
if (pager.num.startsWith('00') && !member.roles.includes('662163685439045632')) {
|
||||
await client.db.PagerNumber.deleteOne({ num: pager.num });
|
||||
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')) {
|
||||
await client.db.PagerNumber.deleteOne({ num: pager.num });
|
||||
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')) {
|
||||
await client.db.PagerNumber.deleteOne({ num: pager.num });
|
||||
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')) {
|
||||
await client.db.PagerNumber.deleteOne({ num: pager.num });
|
||||
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')) {
|
||||
await client.db.PagerNumber.deleteOne({ num: pager.num });
|
||||
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')) {
|
||||
await client.db.PagerNumber.deleteOne({ num: pager.num });
|
||||
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) {
|
||||
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
|
||||
if (!pager && member.roles.includes('662163685439045632')) {
|
||||
let randomPagerNumber: string;
|
||||
|
|
|
@ -63,14 +63,8 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
|||
staff: boolean,
|
||||
locked: boolean,
|
||||
notify: boolean,
|
||||
// inquiries: [{ name: string, reason: string, date: Date }?],
|
||||
// softInquiries: [{name: string, date: Date }?]
|
||||
lastUpdated: Date,
|
||||
pin: number[],
|
||||
/* generalMessagesRatio: number,
|
||||
supportMessagesRatio: number,
|
||||
totalModerations: number,
|
||||
notes: number, */
|
||||
} = {
|
||||
userID: member.user.id,
|
||||
total: 0,
|
||||
|
@ -82,8 +76,6 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
|
|||
staff: false,
|
||||
locked: false,
|
||||
notify: false,
|
||||
// inquiries: [],
|
||||
// softInquiries: [],
|
||||
lastUpdated: new Date(),
|
||||
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);
|
||||
|
||||
/* 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.util.signale.debug(`SCORE SET - ${member.username}\nTotal: ${total}\nActivity: ${activity}\nRoles: ${roles}\nModeration: ${moderation}\nCloud Services: ${cloudServices}\nStaff: ${staff}`);
|
||||
}
|
||||
};
|
||||
await start();
|
||||
|
|
Loading…
Reference in New Issue