diff --git a/src/commands/sss.ts b/src/commands/sss.ts new file mode 100644 index 0000000..7148684 --- /dev/null +++ b/src/commands/sss.ts @@ -0,0 +1,31 @@ +import { Message } from 'eris'; +import { apply as Apply } from '.'; +import { Client, Command } from '../class'; + +import SSS_Create_Account from './sss_create_account'; +import SSS_Password_Reset from './sss_password_reset'; + + +export default class StaffAccountSelfServ extends Command { + public applyCommand: Apply; + + constructor(client: Client) { + super(client); + this.name = 'staff-self-serv'; + this.description = 'Staff IAM Account Self Services System.'; + this.usage = `${this.client.config.prefix}staff-self-serv [arguments]`; + this.aliases = ['sss']; + this.permissions = 1; + this.guildOnly = true; + this.enabled = true; + this.subcmds = [SSS_Create_Account, SSS_Password_Reset]; + } + + public async run(message: Message) { + try { + return this.client.commands.get('help').run(message, [this.name]); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} diff --git a/src/commands/sss_create_account.ts b/src/commands/sss_create_account.ts new file mode 100644 index 0000000..d0f4e45 --- /dev/null +++ b/src/commands/sss_create_account.ts @@ -0,0 +1,109 @@ +import { Message } from 'eris'; +import { apply as Apply } from '.'; +import { Client, Command } from '../class'; + +export default class SSS_Create_Account extends Command { + public applyCommand: Apply; + + constructor(client: Client) { + super(client); + this.name = 'ca'; + this.description = 'Creates a new IAM Account. Most likely, one was already created for you.'; + this.usage = `${this.client.config.prefix}staff-self-serv ca`; + this.permissions = 1; + this.guildOnly = false; + this.enabled = true; + } + + public async run(message: Message) { + try { + const staff = await this.client.db.Staff.findOne({ userID: message.author.id }).lean().exec(); + if (!staff) return this.error(message.channel, 'Staff information not located.'); + + + if (message.member.roles.includes('662163685439045632')) { // Board of Directors + await this.client.util.authClient.createUser({ + email: staff.emailAddress, + name: message.author.username, + user_id: message.author.id, + connection: 'Staff-Database', + email_verified: true, + app_metadata: { + boardOfDirectors: true, + }, + picture: message.author.avatarURL, + }); + } else if (message.member.roles.includes('701454855952138300')) { // Supervisor + await this.client.util.authClient.createUser({ + email: staff.emailAddress, + name: message.author.username, + user_id: message.author.id, + connection: 'Staff-Database', + email_verified: true, + app_metadata: { + supervisor: true, + }, + picture: message.author.avatarURL, + }); + } else if (message.member.roles.includes('701454780828221450')) { // Technician + await this.client.util.authClient.createUser({ + email: staff.emailAddress, + name: message.author.username, + user_id: message.author.id, + connection: 'Staff-Database', + email_verified: true, + app_metadata: { + technician: true, + }, + picture: message.author.avatarURL, + }); + } else if (message.member.roles.includes('455972169449734144')) { // Moderator + await this.client.util.authClient.createUser({ + email: staff.emailAddress, + name: message.author.username, + user_id: message.author.id, + connection: 'Staff-Database', + email_verified: true, + app_metadata: { + moderator: true, + }, + picture: message.author.avatarURL, + }); + } else if (message.member.roles.includes('453689940140883988')) { // Core Team + await this.client.util.authClient.createUser({ + email: staff.emailAddress, + name: message.author.username, + user_id: message.author.id, + connection: 'Staff-Database', + email_verified: true, + app_metadata: { + coreTeam: true, + }, + picture: message.author.avatarURL, + }); + } else if (message.member.roles.includes('701481967149121627')) { // Associates + await this.client.util.authClient.createUser({ + email: staff.emailAddress, + name: message.author.username, + user_id: message.author.id, + connection: 'Staff-Database', + email_verified: true, + app_metadata: { + associate: true, + }, + picture: message.author.avatarURL, + }); + } + + const passwordTicket = await this.client.util.authClient.createPasswordChangeTicket({ + email: staff.emailAddress, + connection_id: 'con_T3ELEx2reigKMSlP', + }); + const channel = await this.client.getDMChannel(message.author.id); + channel.createMessage(`__**Library of Code sp-us | Identity Access Management**__\n\nPlease click the link below to reset your password.\n\n${passwordTicket.ticket}`).catch(() => this.error(message.channel, 'Unable to send you a DM.')); + return message.addReaction('modSuccess:578750988907970567'); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +} diff --git a/src/commands/sss_password_reset.ts b/src/commands/sss_password_reset.ts new file mode 100644 index 0000000..535aab0 --- /dev/null +++ b/src/commands/sss_password_reset.ts @@ -0,0 +1,34 @@ +import { Message } from 'eris'; +import { apply as Apply } from '.'; +import { Client, Command } from '../class'; + +export default class SSS_Password_Reset extends Command { + public applyCommand: Apply; + + constructor(client: Client) { + super(client); + this.name = 'pw'; + this.description = 'Sends a password reset link to your email address.'; + this.usage = `${this.client.config.prefix}staff-self-serv pw`; + this.permissions = 1; + this.guildOnly = false; + this.enabled = true; + } + + public async run(message: Message) { + try { + const staff = await this.client.db.Staff.findOne({ userID: message.author.id }).lean().exec(); + if (!staff) return this.error(message.channel, 'Staff information not located.'); + + const passwordTicket = await this.client.util.authClient.createPasswordChangeTicket({ + email: staff.emailAddress, + connection_id: 'con_T3ELEx2reigKMSlP', + }); + const channel = await this.client.getDMChannel(message.author.id); + channel.createMessage(`__**Library of Code sp-us | Identity Access Management**__\n\nPlease click the link below to reset your password.\n\n${passwordTicket.ticket}`).catch(() => this.error(message.channel, 'Unable to send you a DM.')); + return message.addReaction('modSuccess:578750988907970567'); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +}