buddy

node MVC discord bot
Log | Files | Refs | README

TeamMember.js (1385B)


      1 'use strict';
      2 
      3 const Base = require('./Base');
      4 const { MembershipStates } = require('../util/Constants');
      5 
      6 /**
      7  * Represents a Client OAuth2 Application Team Member.
      8  * @extends {Base}
      9  */
     10 class TeamMember extends Base {
     11   constructor(team, data) {
     12     super(team.client);
     13 
     14     /**
     15      * The Team this member is part of
     16      * @type {Team}
     17      */
     18     this.team = team;
     19 
     20     this._patch(data);
     21   }
     22 
     23   _patch(data) {
     24     /**
     25      * The permissions this Team Member has with regard to the team
     26      * @type {string[]}
     27      */
     28     this.permissions = data.permissions;
     29 
     30     /**
     31      * The permissions this Team Member has with regard to the team
     32      * @type {MembershipStates}
     33      */
     34     this.membershipState = MembershipStates[data.membership_state];
     35 
     36     /**
     37      * The user for this Team Member
     38      * @type {User}
     39      */
     40     this.user = this.client.users.add(data.user);
     41   }
     42 
     43   /**
     44    * The ID of the Team Member
     45    * @type {Snowflake}
     46    * @readonly
     47    */
     48   get id() {
     49     return this.user.id;
     50   }
     51 
     52   /**
     53    * When concatenated with a string, this automatically returns the team members's mention instead of the
     54    * TeamMember object.
     55    * @returns {string}
     56    * @example
     57    * // Logs: Team Member's mention: <@123456789012345678>
     58    * console.log(`Team Member's mention: ${teamMember}`);
     59    */
     60   toString() {
     61     return this.user.toString();
     62   }
     63 }
     64 
     65 module.exports = TeamMember;