summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/structures/Team.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/discord.js/src/structures/Team.js')
-rw-r--r--node_modules/discord.js/src/structures/Team.js117
1 files changed, 117 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/structures/Team.js b/node_modules/discord.js/src/structures/Team.js
new file mode 100644
index 0000000..98eb199
--- /dev/null
+++ b/node_modules/discord.js/src/structures/Team.js
@@ -0,0 +1,117 @@
+'use strict';
+
+const { Collection } = require('@discordjs/collection');
+const { DiscordSnowflake } = require('@sapphire/snowflake');
+const Base = require('./Base');
+const TeamMember = require('./TeamMember');
+
+/**
+ * Represents a Client OAuth2 Application Team.
+ * @extends {Base}
+ */
+class Team extends Base {
+ constructor(client, data) {
+ super(client);
+ this._patch(data);
+ }
+
+ _patch(data) {
+ /**
+ * The Team's id
+ * @type {Snowflake}
+ */
+ this.id = data.id;
+
+ if ('name' in data) {
+ /**
+ * The name of the Team
+ * @type {string}
+ */
+ this.name = data.name;
+ }
+
+ if ('icon' in data) {
+ /**
+ * The Team's icon hash
+ * @type {?string}
+ */
+ this.icon = data.icon;
+ } else {
+ this.icon ??= null;
+ }
+
+ if ('owner_user_id' in data) {
+ /**
+ * The Team's owner id
+ * @type {?Snowflake}
+ */
+ this.ownerId = data.owner_user_id;
+ } else {
+ this.ownerId ??= null;
+ }
+ /**
+ * The Team's members
+ * @type {Collection<Snowflake, TeamMember>}
+ */
+ this.members = new Collection();
+
+ for (const memberData of data.members) {
+ const member = new TeamMember(this, memberData);
+ this.members.set(member.id, member);
+ }
+ }
+
+ /**
+ * The owner of this team
+ * @type {?TeamMember}
+ * @readonly
+ */
+ get owner() {
+ return this.members.get(this.ownerId) ?? null;
+ }
+
+ /**
+ * The timestamp the team was created at
+ * @type {number}
+ * @readonly
+ */
+ get createdTimestamp() {
+ return DiscordSnowflake.timestampFrom(this.id);
+ }
+
+ /**
+ * The time the team was created at
+ * @type {Date}
+ * @readonly
+ */
+ get createdAt() {
+ return new Date(this.createdTimestamp);
+ }
+
+ /**
+ * A link to the team's icon.
+ * @param {ImageURLOptions} [options={}] Options for the image URL
+ * @returns {?string}
+ */
+ iconURL(options = {}) {
+ return this.icon && this.client.rest.cdn.teamIcon(this.id, this.icon, options);
+ }
+
+ /**
+ * When concatenated with a string, this automatically returns the Team's name instead of the
+ * Team object.
+ * @returns {string}
+ * @example
+ * // Logs: Team name: My Team
+ * console.log(`Team name: ${team}`);
+ */
+ toString() {
+ return this.name;
+ }
+
+ toJSON() {
+ return super.toJSON({ createdTimestamp: true });
+ }
+}
+
+module.exports = Team;