Skip to content

Commit

Permalink
Add new props to structure
Browse files Browse the repository at this point in the history
  • Loading branch information
conorwastakenwastaken committed Sep 30, 2021
1 parent daedb2b commit 3c26ee7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ module.exports.GUILD_BANNER = (guildID, guildBanner)
module.exports.GUILD_DISCOVERY_SPLASH = (guildID, guildDiscoverySplash) => `/discovery-splashes/${guildID}/${guildDiscoverySplash}`;
module.exports.GUILD_ICON = (guildID, guildIcon) => `/icons/${guildID}/${guildIcon}`;
module.exports.GUILD_SPLASH = (guildID, guildSplash) => `/splashes/${guildID}/${guildSplash}`;
module.exports.TEAM_ICON = (teamID, teamIcon) => `/team-icons/${teamID}/${teamIcon}`;
module.exports.ROLE_ICON = (roleID, roleIcon) => `/role-icons/${roleID}/${roleIcon}`;
module.exports.TEAM_ICON = (teamID, teamIcon) => `/team-icons/${teamID}/${teamIcon}`;
module.exports.USER_AVATAR = (userID, userAvatar) => `/avatars/${userID}/${userAvatar}`;

// Client Endpoints
Expand Down
20 changes: 18 additions & 2 deletions lib/structures/Role.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";

const Base = require("./Base");
const Endpoints = require("../rest/Endpoints");
const Permission = require("./Permission");

/**
* Represents a role
* @prop {Number} color The hex color of the role in base 10
* @prop {Number} createdAt Timestamp of the role's creation
* @prop {Boolean} hoist Whether users with this role are hoisted in the user list or not
* @prop {String?} icon The hash of the role's icon image, or null if no icon
* @prop {String?} iconURL The URL of the role's icon image
* @prop {String} id The ID of the role
* @prop {Object} json Generates a JSON representation of the role permissions
* @prop {Guild} guild The guild that owns the role
Expand All @@ -21,6 +24,7 @@ const Permission = require("./Permission");
* @prop {String?} tags.bot_id The ID of the bot associated with the role
* @prop {String?} tags.integration_id The ID of the integration associated with the role
* @prop {Boolean?} tags.premium_subscriber Whether the role is the guild's premium subscriber role
* @prop {String?} unicodeEmoji Unicode emoji for the role
*/
class Role extends Base {
constructor(data, guild) {
Expand Down Expand Up @@ -57,16 +61,26 @@ class Role extends Base {
this.tags.premium_subscriber = true;
}
}
if(data.icon !== undefined) {
this.icon = data.icon;
}
if(data.unicode_emoji !== undefined) {
this.unicodeEmoji = data.unicode_emoji;
}
}

get mention() {
return `<@&${this.id}>`;
get iconURL() {
return this.icon ? this.guild.shard.client._formatImage(Endpoints.ROLE_ICON(this.id, this.icon)) : null;
}

get json() {
return this.permissions.json;
}

get mention() {
return `<@&${this.id}>`;
}

/**
* Delete the role
* @arg {String} [reason] The reason to be displayed in audit logs
Expand Down Expand Up @@ -104,12 +118,14 @@ class Role extends Base {
return super.toJSON([
"color",
"hoist",
"icon",
"managed",
"mentionable",
"name",
"permissions",
"position",
"tags",
"unicodeEmoji",
...props
]);
}
Expand Down

0 comments on commit 3c26ee7

Please sign in to comment.