Skip to content

Commit

Permalink
feat(Role): Add role flags & update role tags (#1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
conorwastakenwastaken authored Feb 4, 2024
1 parent f259808 commit e54cc76
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ declare namespace Eris {
}
interface OldRole {
color: number;
flags: number;
hoist: boolean;
icon: string | null;
managed: boolean;
Expand Down Expand Up @@ -1595,6 +1596,7 @@ declare namespace Eris {
}
interface PartialRole {
color?: number;
flags?: number;
hoist?: boolean;
id: string;
mentionable?: boolean;
Expand All @@ -1615,6 +1617,9 @@ declare namespace Eris {
bot_id?: string;
integration_id?: string;
premium_subscriber?: true;
subscription_listing_id?: string;
available_for_purchase?: true;
guild_connections?: true;
}

// Thread
Expand Down Expand Up @@ -2262,6 +2267,9 @@ declare namespace Eris {
NITRO_CLASSIC: 1;
NITRO: 2;
};
RoleFlags: {
IN_PROMPT: 1
};
StageInstancePrivacyLevel: {
PUBLIC: 1;
GUILD_ONLY: 2;
Expand Down Expand Up @@ -3706,6 +3714,7 @@ declare namespace Eris {
export class Role extends Base {
color: number;
createdAt: number;
flags: number;
guild: Guild;
hoist: boolean;
icon: string | null;
Expand Down
4 changes: 4 additions & 0 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ module.exports.PremiumTypes = {
NITRO: 2
};

module.exports.RoleFlags = {
IN_PROMPT: 1 << 0
};

module.exports.StageInstancePrivacyLevel = {
PUBLIC: 1,
GUILD_ONLY: 2
Expand Down
6 changes: 4 additions & 2 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,7 @@ class Shard extends EventEmitter {
}
const oldRole = {
color: role.color,
flags: role.flags,
hoist: role.hoist,
icon: role.icon,
managed: role.managed,
Expand All @@ -1583,9 +1584,10 @@ class Shard extends EventEmitter {
* @prop {Role} role The updated role
* @prop {Object} oldRole The old role data
* @prop {Number} oldRole.color The hex color of the role in base 10
* @prop {Boolean} oldRole.hoist Whether users with this role are hoisted in the user list or not
* @prop {Number} oldRole.flags The flags of the role (see constants)
* @prop {Boolean} oldRole.hoist Whether users with the role are hoisted in the user list or not
* @prop {String?} oldRole.icon The hash of the role's icon, or null if no icon
* @prop {Boolean} oldRole.managed Whether a guild integration manages this role or not
* @prop {Boolean} oldRole.managed Whether a guild integration manages the role or not
* @prop {Boolean} oldRole.mentionable Whether the role is mentionable or not
* @prop {String} oldRole.name The name of the role
* @prop {Permission} oldRole.permissions The permissions number of the role
Expand Down
19 changes: 15 additions & 4 deletions lib/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ 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 {Number} flags The flags of the role (see constants)
* @prop {Guild} guild The guild that owns the role
* @prop {Boolean} hoist Whether users with the role are hoisted in the user list or not
* @prop {String?} icon The hash of the role's icon, or null if no icon
* @prop {String?} iconURL The URL of the role's icon
* @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
* @prop {Boolean} managed Whether a guild integration manages this role or not
* @prop {Boolean} managed Whether a guild integration manages the role or not
* @prop {String} mention A string that mentions the role
* @prop {Boolean} mentionable Whether the role is mentionable or not
* @prop {String} name The name of the role
Expand All @@ -24,6 +25,9 @@ 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?} tags.subscription_listing_id The id of the role's subscription sku and listing
* @prop {Boolean?} tags.available_for_purchase Whether the role is available for purchase
* @prop {Boolean?} tags.guild_connections Whether the role is a guild's linked role
* @prop {String?} unicodeEmoji Unicode emoji for the role
*/
class Role extends Base {
Expand Down Expand Up @@ -57,7 +61,11 @@ class Role extends Base {
}
if(data.tags !== undefined) {
this.tags = data.tags;
if(this.tags.premium_subscriber === null) {
if(this.tags.available_for_purchase === null) {
this.tags.available_for_purchase = true;
} else if(this.tags.guild_connections === null) {
this.tags.guild_connections = true;
} else if(this.tags.premium_subscriber === null) {
this.tags.premium_subscriber = true;
}
}
Expand All @@ -67,6 +75,9 @@ class Role extends Base {
if(data.unicode_emoji !== undefined) {
this.unicodeEmoji = data.unicode_emoji;
}
if(data.flags !== undefined) {
this.flags = data.flags;
}
}

get iconURL() {
Expand Down

0 comments on commit e54cc76

Please sign in to comment.