add auto create/delete IAMs

merge-requests/25/merge
Matthew 2021-06-04 23:01:35 -04:00
parent 9ea79a5ebc
commit ade901e6be
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 107 additions and 5 deletions

View File

@ -90,31 +90,37 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
if (!pager) continue; if (!pager) continue;
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 });
await client.util.authClient.deleteUser({ id: member.id });
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'); 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 });
await client.util.authClient.deleteUser({ id: member.id });
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'); 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 });
await client.util.authClient.deleteUser({ id: member.id });
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'); 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 });
await client.util.authClient.deleteUser({ id: member.id });
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'); 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 });
await client.util.authClient.deleteUser({ id: member.id });
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'); 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 });
await client.util.authClient.deleteUser({ id: member.id });
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'); await client.util.removeUserFromMailingList(pager.emailAddresses[0], 'all-staff');
} }
@ -149,9 +155,25 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue; if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
pager = await newNumber.save(); pager = await newNumber.save();
await client.util.authClient.createUser({
email: acknowledgement.emailAddress,
name: member.username,
user_id: member.id,
connection: 'Staff-Database',
email_verified: true,
app_metadata: {
boardOfDirectors: true,
},
picture: member.avatarURL,
});
const passwordTicket = await client.util.authClient.createPasswordChangeTicket({
email: acknowledgement.emailAddress,
connection_id: 'con_T3ELEx2reigKMSlP',
});
logNewPager(client, randomPagerNumber, member); logNewPager(client, randomPagerNumber, member);
client.getDMChannel(member.id).then((chan) => { client.getDMChannel(member.id).then((chan) => {
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`); chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
chan.createMessage(`__**Library of Code sp-us | Identity Access Management**__\n__Reset Password__\n\nPlease click on the link below to change your IAM password.\n${passwordTicket.ticket}`);
}); });
} else if (!pager && member.roles.includes('701454855952138300')) { } else if (!pager && member.roles.includes('701454855952138300')) {
// Supervisors // Supervisors
@ -173,10 +195,26 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue; if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save(); pager = await newNumber.save();
await client.util.authClient.createUser({
email: acknowledgement.emailAddress,
name: member.username,
user_id: member.id,
connection: 'Staff-Database',
email_verified: true,
app_metadata: {
supervisor: true,
},
picture: member.avatarURL,
});
const passwordTicket = await client.util.authClient.createPasswordChangeTicket({
email: acknowledgement.emailAddress,
connection_id: 'con_T3ELEx2reigKMSlP',
});
logNewPager(client, randomPagerNumber, member);
client.getDMChannel(member.id).then((chan) => { client.getDMChannel(member.id).then((chan) => {
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`); chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
chan.createMessage(`__**Library of Code sp-us | Identity Access Management**__\n__Reset Password__\n\nPlease click on the link below to change your IAM password.\n${passwordTicket.ticket}`);
}); });
} else if (!pager && member.roles.includes('701454780828221450')) { } else if (!pager && member.roles.includes('701454780828221450')) {
// Technicians // Technicians
@ -199,10 +237,26 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue; if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save(); pager = await newNumber.save();
await client.util.authClient.createUser({
email: acknowledgement.emailAddress,
name: member.username,
user_id: member.id,
connection: 'Staff-Database',
email_verified: true,
app_metadata: {
technician: true,
},
picture: member.avatarURL,
});
const passwordTicket = await client.util.authClient.createPasswordChangeTicket({
email: acknowledgement.emailAddress,
connection_id: 'con_T3ELEx2reigKMSlP',
});
logNewPager(client, randomPagerNumber, member);
client.getDMChannel(member.id).then((chan) => { client.getDMChannel(member.id).then((chan) => {
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`); chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
chan.createMessage(`__**Library of Code sp-us | Identity Access Management**__\n__Reset Password__\n\nPlease click on the link below to change your IAM password.\n${passwordTicket.ticket}`);
}); });
} else if (!pager && member.roles.includes('455972169449734144')) { } else if (!pager && member.roles.includes('455972169449734144')) {
// Moderators // Moderators
@ -225,10 +279,26 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue; if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save(); pager = await newNumber.save();
await client.util.authClient.createUser({
email: acknowledgement.emailAddress,
name: member.username,
user_id: member.id,
connection: 'Staff-Database',
email_verified: true,
app_metadata: {
moderator: true,
},
picture: member.avatarURL,
});
const passwordTicket = await client.util.authClient.createPasswordChangeTicket({
email: acknowledgement.emailAddress,
connection_id: 'con_T3ELEx2reigKMSlP',
});
logNewPager(client, randomPagerNumber, member);
client.getDMChannel(member.id).then((chan) => { client.getDMChannel(member.id).then((chan) => {
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`); chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
chan.createMessage(`__**Library of Code sp-us | Identity Access Management**__\n__Reset Password__\n\nPlease click on the link below to change your IAM password.\n${passwordTicket.ticket}`);
}); });
} else if (!pager && member.roles.includes('453689940140883988')) { } else if (!pager && member.roles.includes('453689940140883988')) {
// Core Team // Core Team
@ -251,10 +321,26 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue; if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save(); pager = await newNumber.save();
await client.util.authClient.createUser({
email: acknowledgement.emailAddress,
name: member.username,
user_id: member.id,
connection: 'Staff-Database',
email_verified: true,
app_metadata: {
coreTeam: true,
},
picture: member.avatarURL,
});
const passwordTicket = await client.util.authClient.createPasswordChangeTicket({
email: acknowledgement.emailAddress,
connection_id: 'con_T3ELEx2reigKMSlP',
});
logNewPager(client, randomPagerNumber, member);
client.getDMChannel(member.id).then((chan) => { client.getDMChannel(member.id).then((chan) => {
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`); chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
chan.createMessage(`__**Library of Code sp-us | Identity Access Management**__\n__Reset Password__\n\nPlease click on the link below to change your IAM password.\n${passwordTicket.ticket}`);
}); });
} else if (!pager && member.roles.includes('701481967149121627')) { } else if (!pager && member.roles.includes('701481967149121627')) {
// Associates // Associates
@ -277,10 +363,26 @@ export default async function departmentPager(client: Client): Promise<NodeJS.Ti
discordIDs: [member.id], discordIDs: [member.id],
}); });
if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue; if (await client.db.PagerNumber.findOne({ num: randomPagerNumber })) continue;
logNewPager(client, randomPagerNumber, member);
pager = await newNumber.save(); pager = await newNumber.save();
await client.util.authClient.createUser({
email: acknowledgement.emailAddress,
name: member.username,
user_id: member.id,
connection: 'Staff-Database',
email_verified: true,
app_metadata: {
associate: true,
},
picture: member.avatarURL,
});
const passwordTicket = await client.util.authClient.createPasswordChangeTicket({
email: acknowledgement.emailAddress,
connection_id: 'con_T3ELEx2reigKMSlP',
});
logNewPager(client, randomPagerNumber, member);
client.getDMChannel(member.id).then((chan) => { client.getDMChannel(member.id).then((chan) => {
chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`); chan.createMessage(`__**Pager Number Creation**__\nYour individual pager number has been automatically created. Your number (PN) is ${randomPagerNumber}.`);
chan.createMessage(`__**Library of Code sp-us | Identity Access Management**__\n__Reset Password__\n\nPlease click on the link below to change your IAM password.\n${passwordTicket.ticket}`);
}); });
} }
} }