Merge pull request #455 from TheDevYellowy/main

feat: add the ability to delete a team
This commit is contained in:
Elysia 2022-12-22 18:39:39 +07:00 committed by GitHub
commit 0d99a2862a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -11,6 +11,8 @@ const Messages = {
TOKEN_INVALID: 'An invalid token was provided.', TOKEN_INVALID: 'An invalid token was provided.',
TOKEN_MISSING: 'Request to use token, but token was unavailable to the client.', 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_CLOSE_REQUESTED: 'WebSocket closed due to user request.',
WS_CONNECTION_EXISTS: 'There is already an existing WebSocket connection.', WS_CONNECTION_EXISTS: 'There is already an existing WebSocket connection.',
WS_NOT_OPEN: (data = 'data') => `WebSocket not open to send ${data}`, WS_NOT_OPEN: (data = 'data') => `WebSocket not open to send ${data}`,

View File

@ -103,15 +103,18 @@ class Team extends Base {
/** /**
* Invite a team member to the team * Invite a team member to the team
* @param {User} user The user to invite 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<TeamMember>} * @returns {Promise<TeamMember>}
*/ */
async inviteMember(user, MFACode) { async inviteMember(user, MFACode) {
if (!(user instanceof User)) return new Error('TEAM_MEMBER_FORMAT'); if (!(user instanceof User)) return new Error('TEAM_MEMBER_FORMAT');
const regex = /([0-9]{6})/g;
const payload = { const payload = {
username: user.username, username: user.username,
discriminator: user.discriminator, discriminator: user.discriminator,
}; };
if (MFACode && !regex.test(MFACode)) return new Error('MFA_INVALID');
if (MFACode) payload.code = MFACode; if (MFACode) payload.code = MFACode;
const member = await this.client.api.teams(this.id).members.post({ const member = await this.client.api.teams(this.id).members.post({
@ -125,9 +128,23 @@ class Team extends Base {
/** /**
* Remove a member from the team * Remove a member from the team
* @param {Snowflake} userID The ID of the user you want to remove * @param {Snowflake} userID The ID of the user you want to remove
* @returns {boolean}
*/ */
async removeMember(userID) { async removeMember(userID) {
await this.client.api.teams[this.id].members[userID].delete(); await this.client.api.teams[this.id].members[userID].delete();
return this.members.delete(userID);
}
/**
* Delete this team
* @param {number} MFACode The 2fa code
* @returns {Promise<boolean>}
*/
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);
} }
/** /**

4
typings/index.d.ts vendored
View File

@ -457,6 +457,7 @@ export class DeveloperPortalManager extends BaseManager {
public applications: Collection<Snowflake, DeveloperPortalApplication>; public applications: Collection<Snowflake, DeveloperPortalApplication>;
public teams: Collection<Snowflake, Team>; public teams: Collection<Snowflake, Team>;
public fetch(): Promise<DeveloperPortalManager>; public fetch(): Promise<DeveloperPortalManager>;
public createTeam(name: string): Promise<Team>;
public createApplication(name: string, teamId?: Team | Snowflake): Promise<DeveloperPortalApplication>; public createApplication(name: string, teamId?: Team | Snowflake): Promise<DeveloperPortalApplication>;
public deleteApplication(id: Snowflake, MFACode?: number): Promise<undefined>; public deleteApplication(id: Snowflake, MFACode?: number): Promise<undefined>;
} }
@ -2889,6 +2890,9 @@ export class Team extends Base {
public readonly createdTimestamp: number; public readonly createdTimestamp: number;
public iconURL(options?: StaticImageURLOptions): string | null; public iconURL(options?: StaticImageURLOptions): string | null;
public inviteMemeber(user: User, MFACode: number): Promise<TeamMember>;
public removeMemeber(userID: Snowflake): boolean;
public delete(MFACode: string): Promise<boolean>;
public toJSON(): unknown; public toJSON(): unknown;
public toString(): string; public toString(): string;
} }