Team.js
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
const Base = require('./Base');
const TeamMember = require('./TeamMember');
const Collection = require('../util/Collection');
const Snowflake = require('../util/Snowflake');
/**
* Represents a Client OAuth2 Application Team.
* @extends {Base}
*/
class Team extends Base {
constructor(client, data) {
super(client);
this._patch(data);
}
_patch(data) {
/**
* The ID of the Team
* @type {Snowflake}
*/
this.id = data.id;
/**
* The name of the Team
* @type {string}
*/
this.name = data.name;
/**
* The Team's icon hash
* @type {?string}
*/
this.icon = data.icon || null;
/**
* The Team's owner id
* @type {?string}
*/
this.ownerID = data.owner_user_id || 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 Snowflake.deconstruct(this.id).timestamp;
}
/**
* The time the team was created at
* @type {Date}
* @readonly
*/
get createdAt() {
return new Date(this.createdTimestamp);
}
/**
* A link to the teams's icon.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @returns {?string} URL to the icon
*/
iconURL({ format, size } = {}) {
if (!this.icon) return null;
return this.client.rest.cdn.TeamIcon(this.id, this.icon, { format, size });
}
/**
* 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;