From 047c4d000546079d15e07af4bc94ca47c0260c8e Mon Sep 17 00:00:00 2001 From: TheDevYellowy Date: Thu, 22 Dec 2022 03:37:59 -0800 Subject: [PATCH] refactor: add to index.d.ts & change MFACode type --- src/errors/Messages.js | 2 ++ src/structures/Team.js | 15 +++++++++++---- typings/index.d.ts | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index d6ea731..4c2958b 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -11,6 +11,8 @@ const Messages = { TOKEN_INVALID: 'An invalid token was provided.', TOKEN_MISSING: 'Request to use token, but token was unavailable to the client.', + MFA_INVALID: 'An invalid mfa code was provided', + WS_CLOSE_REQUESTED: 'WebSocket closed due to user request.', WS_CONNECTION_EXISTS: 'There is already an existing WebSocket connection.', WS_NOT_OPEN: (data = 'data') => `WebSocket not open to send ${data}`, diff --git a/src/structures/Team.js b/src/structures/Team.js index e2745a2..85ed2c9 100644 --- a/src/structures/Team.js +++ b/src/structures/Team.js @@ -103,15 +103,18 @@ class Team extends Base { /** * Invite a team member to the team * @param {User} user The user to invite to the team - * @param {string} MFACode The mfa code + * @param {number} MFACode The mfa code * @returns {Promise} */ async inviteMember(user, MFACode) { if (!(user instanceof User)) return new Error('TEAM_MEMBER_FORMAT'); + const regex = /([0-9]{6})/g; + const payload = { username: user.username, discriminator: user.discriminator, }; + if (MFACode && !regex.test(MFACode)) return new Error('MFA_INVALID'); if (MFACode) payload.code = MFACode; const member = await this.client.api.teams(this.id).members.post({ @@ -125,18 +128,22 @@ class Team extends Base { /** * Remove a member from the team * @param {Snowflake} userID The ID of the user you want to remove + * @returns {boolean} */ async removeMember(userID) { await this.client.api.teams[this.id].members[userID].delete(); + return this.members.delete(userID); } /** * Delete this team - * @param {string} code The 2fa code + * @param {number} MFACode The 2fa code * @returns {Promise} */ - async delete(code) { - await this.client.api.teams[this.id].delete({ data: { code: code } }); + async delete(MFACode) { + const regex = /([0-9]{6})/g; + if (!regex.test(MFACode)) return new Error('MFA_INVALID'); + await this.client.api.teams[this.id].delete({ data: { code: MFACode } }); return this.client.developerPortal.teams.delete(this.id); } diff --git a/typings/index.d.ts b/typings/index.d.ts index b9d56a4..e46d256 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -457,6 +457,7 @@ export class DeveloperPortalManager extends BaseManager { public applications: Collection; public teams: Collection; public fetch(): Promise; + public createTeam(name: string): Promise; public createApplication(name: string, teamId?: Team | Snowflake): Promise; public deleteApplication(id: Snowflake, MFACode?: number): Promise; } @@ -2889,6 +2890,9 @@ export class Team extends Base { public readonly createdTimestamp: number; public iconURL(options?: StaticImageURLOptions): string | null; + public inviteMemeber(user: User, MFACode: number): Promise; + public removeMemeber(userID: Snowflake): boolean; + public delete(MFACode: string): Promise; public toJSON(): unknown; public toString(): string; }