New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: teams support #3350
Merged
Merged
feature: teams support #3350
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0e4e901
basic teams support
bdistin 0478d27
export Team & TeamMember
bdistin 23373c8
use typedef
bdistin 4310e7c
typings and some fixes
bdistin 42ccff6
Update src/structures/TeamMember.js
bdistin 9aeb74f
fix Team#iconURL()
bdistin d021c81
fix typings and a bug
bdistin 0c6b0a8
fix states start at 1
bdistin 73b5b7c
team icon hash can be null
bdistin 5888800
fix owner typings
bdistin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
'use strict'; | ||
|
||
const Snowflake = require('../util/Snowflake'); | ||
const Collection = require('../util/Collection'); | ||
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 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; | ||
|
||
/** | ||
* 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.client, 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 app was created at | ||
* @type {number} | ||
* @readonly | ||
*/ | ||
get createdTimestamp() { | ||
return Snowflake.deconstruct(this.id).timestamp; | ||
} | ||
|
||
/** | ||
* The time the app was created at | ||
* @type {Date} | ||
* @readonly | ||
*/ | ||
get createdAt() { | ||
return new Date(this.createdTimestamp); | ||
} | ||
|
||
/** | ||
* A link to the application'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.AppIcon(this.id, this.icon, { format, size }); | ||
bdistin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* 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: ${application}`); | ||
bdistin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
toString() { | ||
return this.name; | ||
} | ||
|
||
toJSON() { | ||
return super.toJSON({ createdTimestamp: true }); | ||
} | ||
} | ||
|
||
module.exports = Team; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
const Base = require('./Base'); | ||
const { MembershipStates } = require('../util/Constants'); | ||
|
||
/** | ||
* Represents a Client OAuth2 Application Team Member. | ||
* @extends {Base} | ||
*/ | ||
class TeamMember extends Base { | ||
constructor(client, team, data) { | ||
super(client); | ||
|
||
/** | ||
* The Team | ||
bdistin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @type {Team} | ||
*/ | ||
this.team = team; | ||
|
||
this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** | ||
* The ID of the Team Member | ||
* @type {Snowflake} | ||
*/ | ||
this.id = data.user.id; | ||
bdistin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* The permissions this Team Member has with reguard to the team | ||
* @type {string[]} | ||
*/ | ||
this.permissions = data.permissions; | ||
|
||
/** | ||
* The permissions this Team Member has with reguard to the team | ||
* @type {MembershipStates} | ||
*/ | ||
this.membershipState = MembershipStates[data.membership_state]; | ||
|
||
/** | ||
* The user for this Team Member | ||
* @type {User} | ||
*/ | ||
this.user = this.client.users.add(data.user); | ||
} | ||
|
||
/** | ||
* When concatenated with a string, this automatically returns the team members's name instead of the | ||
* TeamMember object. | ||
* @returns {string} | ||
* @example | ||
* // Logs: Team Member's username: Hydrabolt | ||
* console.log(`Team Member's name: ${teamMember}`); | ||
*/ | ||
toString() { | ||
return this.user.username; | ||
bdistin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
toJSON() { | ||
bdistin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return super.toJSON(); | ||
bdistin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
module.exports = TeamMember; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Owner and Team should be separated in my opinion. While the owner of an app that is in a team is fake, it's still an user. A warning should be added instead