From c12636714065d756166fc473de42bff04e24fa86 Mon Sep 17 00:00:00 2001 From: Asad <105254706+AsadHumayun@users.noreply.github.com> Date: Tue, 27 Jan 2026 22:59:42 +0000 Subject: [PATCH] feat(structures): add Team structure (#11396) * feat(structures): add and update barrel exports in prep for new struct * feat(structures): add TeamMember substructure * feat(structures): add Team structure * chore(structures): add ownerUserId attribute back * chore(structures): add teamId attribute * docs(structures): correctly use see/link blocks and cleanup --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/structures/src/index.ts | 1 + packages/structures/src/teams/Team.ts | 69 +++++++++++++++++++++ packages/structures/src/teams/TeamMember.ts | 49 +++++++++++++++ packages/structures/src/teams/index.ts | 2 + 4 files changed, 121 insertions(+) create mode 100644 packages/structures/src/teams/Team.ts create mode 100644 packages/structures/src/teams/TeamMember.ts create mode 100644 packages/structures/src/teams/index.ts diff --git a/packages/structures/src/index.ts b/packages/structures/src/index.ts index 6fa8d797f..22c9c5592 100644 --- a/packages/structures/src/index.ts +++ b/packages/structures/src/index.ts @@ -8,6 +8,7 @@ export * from './invites/index.js'; export * from './messages/index.js'; export * from './polls/index.js'; export * from './stickers/index.js'; +export * from './teams/index.js'; export * from './users/index.js'; export * from './Structure.js'; export * from './subscriptions/index.js'; diff --git a/packages/structures/src/teams/Team.ts b/packages/structures/src/teams/Team.ts new file mode 100644 index 000000000..76ebb0f75 --- /dev/null +++ b/packages/structures/src/teams/Team.ts @@ -0,0 +1,69 @@ +import { DiscordSnowflake } from '@sapphire/snowflake'; +import type { APITeam } from 'discord-api-types/v10'; +import { Structure } from '../Structure.js'; +import { kData } from '../utils/symbols.js'; +import { isIdSet } from '../utils/type-guards.js'; +import type { Partialize } from '../utils/types.js'; + +/** + * Represents any team on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + * @remarks has substructure `TeamMember` which needs to be instantiated and stored by an extending class using it + */ +export class Team extends Structure { + /** + * The template used for removing data from the raw data stored for each team. + */ + public static override readonly DataTemplate: Partial = {}; + + /** + * @param data - The raw data received from the API for the team. + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * Hash of the image of the team's icon + */ + public get icon() { + return this[kData].icon; + } + + /** + * The unique id of the team + */ + public get id() { + return this[kData].id; + } + + /** + * Name of the team + */ + public get name() { + return this[kData].name; + } + + /** + * User ID of the current team owner + */ + public get ownerUserId() { + return this[kData].owner_user_id; + } + + /** + * The timestamp the team was created at + */ + public get createdTimestamp() { + return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null; + } + + /** + * The time the team was created at + */ + public get createdAt() { + const createdTimestamp = this.createdTimestamp; + return createdTimestamp ? new Date(createdTimestamp) : null; + } +} diff --git a/packages/structures/src/teams/TeamMember.ts b/packages/structures/src/teams/TeamMember.ts new file mode 100644 index 000000000..5e1ea2f94 --- /dev/null +++ b/packages/structures/src/teams/TeamMember.ts @@ -0,0 +1,49 @@ +import type { APITeamMember } from 'discord-api-types/v10'; +import { Structure } from '../Structure.js'; +import { kData } from '../utils/symbols.js'; +import type { Partialize } from '../utils/types.js'; + +/** + * Represents any team member on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + * @remarks has substructure `User` which needs to be instantiated and stored by an extending class using it + */ +export class TeamMember extends Structure { + /** + * The template used for removing data from the raw data stored for each team member + */ + public static override readonly DataTemplate: Partial = {}; + + /** + * @param data - The raw data received from the API for the team member + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * User's membership state on the team + * + * @see {@link https://discord.com/developers/docs/topics/teams#data-models-membership-state-enum} + */ + public get membershipState() { + return this[kData].membership_state; + } + + /** + * Id of the parent team of which they are a member + */ + public get teamId() { + return this[kData].team_id; + } + + /** + * Role of the team member + * + * @see {@link https://discord.com/developers/docs/topics/teams#team-member-roles-team-member-role-types} + */ + public get role() { + return this[kData].role; + } +} diff --git a/packages/structures/src/teams/index.ts b/packages/structures/src/teams/index.ts new file mode 100644 index 000000000..0af80814c --- /dev/null +++ b/packages/structures/src/teams/index.ts @@ -0,0 +1,2 @@ +export * from './Team.js'; +export * from './TeamMember.js';