Skip to content
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

feat(Role): role tags #4628

Merged
merged 24 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f878bd4
feat(Role): role tags
almostSouji Jul 11, 2020
9aaa93c
fix(RoleManager): fix js docs and mark nullable
almostSouji Jul 11, 2020
15d3d7f
fix(Role): typings tags are be null, not undefined
almostSouji Jul 11, 2020
ab7cb31
fix(Role): getters should actually return a bool
almostSouji Jul 11, 2020
72c2d01
fix(RoleManager): typo
almostSouji Jul 11, 2020
830c45c
fix(Role): should always return a boolean
almostSouji Jul 11, 2020
54c7c32
fix(Gmrm): getter should return null
almostSouji Jul 11, 2020
ac63b62
fix(RoleManager): getters should return null
almostSouji Jul 11, 2020
190b101
fix: typing getters should return null
almostSouji Jul 11, 2020
240780f
fix(Role): docs grammar and consistency
almostSouji Jul 11, 2020
de4b61a
chore: prefer in operator over Reflect#has
almostSouji Jul 11, 2020
c619796
feat(GmRm): botRole getter
almostSouji Jul 11, 2020
d6631e3
fix(GmRm): use the actual properties
almostSouji Jul 11, 2020
42abed5
feat(RoleManager): rem myRole in pref o botRoleFor
almostSouji Jul 11, 2020
a95bbba
fix(Role): remove obsolete is- getters
almostSouji Jul 11, 2020
8db00f6
fix: checking tags after getter removal
almostSouji Jul 11, 2020
d4bc55e
chore: identifier naming consistency
almostSouji Jul 11, 2020
3e6091d
chore: prefer explicit true type over boolean
almostSouji Jul 11, 2020
f0b6741
fix: typo
almostSouji Jul 11, 2020
1cd5808
feat(Integration): Add Integration#roles getter (#1)
vaporoxx Jul 12, 2020
066eaa0
fix(RoleManager): remove bot check r:partials
almostSouji Aug 30, 2020
b1fe25c
feat(RoleManager): robustness against uncached u
almostSouji Aug 30, 2020
455d9a5
Merge branch 'master' into feat-role-tags
almostSouji Nov 25, 2020
258d6a5
docs: possibly undefined
almostSouji Nov 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/managers/GuildMemberRoleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class GuildMemberRoleManager {
return this._roles.reduce((prev, role) => (role.comparePositionTo(prev) > 0 ? role : prev), this._roles.first());
}

/**
* The premium subscriber role of the guild, if present on the member
* @type {?Role}
* @readonly
*/
get premiumSubscriberRole() {
return this.cache.find(role => role.premiumSubscriberRole) || null;
}

/**
* Adds a role (or multiple roles) to the member.
* @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to add
Expand Down
18 changes: 18 additions & 0 deletions src/managers/RoleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ class RoleManager extends BaseManager {
return this.cache.get(this.guild.id);
}

/**
* The premium subscriber role of the guild, if any
* @type {?Role}
* @readonly
*/
get premiumSubscriberRole() {
return this.cache.find(role => role.premiumSubscriberRole) || null;
}

/**
* The role associated with the client user of the guild, if any
* @type {?Role}
* @readonly
*/
get myRole() {
return this.cache.find(role => role.isMyRole) || null;
}

/**
* The role with the highest position in the cache
* @type {Role}
Expand Down
38 changes: 38 additions & 0 deletions src/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,44 @@ class Role extends Base {
* @type {boolean}
*/
this.deleted = false;

/**
* The tags this role has
* @type {?Object}
* @property {?Snowflake} botID The id of the bot this role belongs to
* @property {?Snowflake} integrationID The id of the integration this role belongs to
* @property {?boolean} premiumSubcriberRole Whether this is the guilds premium subscription role
almostSouji marked this conversation as resolved.
Show resolved Hide resolved
*/
this.tags = data.tags ? {} : null;
if (data.tags) {
if (Reflect.has(data.tags, 'bot_id')) {
this.tags.botID = data.tags.bot_id;
}
if (Reflect.has(data.tags, 'integration_id')) {
this.tags.integrationID = data.tags.integration_id;
}
if (Reflect.has(data.tags, 'premium_subscriber')) {
this.tags.premiumSubscriberRole = true;
}
}
}

/**
* Whether this role is the guilds premium subscription role
almostSouji marked this conversation as resolved.
Show resolved Hide resolved
* @type {boolean}
* @readonly
*/
get isPremiumSubscriberRole() {
return Boolean(this.tags && this.tags.premiumSubscriberRole);
}

/**
* Whether this role is the role associated with the logged in bot user
almostSouji marked this conversation as resolved.
Show resolved Hide resolved
* @type {boolean}
* @readonly
*/
get isMyRole() {
return Boolean(this.tags && this.tags.botID === this.client.user.id);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,13 +1241,16 @@ declare module 'discord.js' {
public readonly hexColor: string;
public hoist: boolean;
public id: Snowflake;
public readonly isMyRole: boolean;
public readonly isPremiumSubscriberRole: boolean;
public managed: boolean;
public readonly members: Collection<Snowflake, GuildMember>;
public mentionable: boolean;
public name: string;
public permissions: Readonly<Permissions>;
public readonly position: number;
public rawPosition: number;
public tags: RoleTagData | null;
public comparePositionTo(role: Role): number;
public delete(reason?: string): Promise<Role>;
public edit(data: RoleData, reason?: string): Promise<Role>;
Expand Down Expand Up @@ -1899,6 +1902,7 @@ declare module 'discord.js' {
public readonly hoist: Role | null;
public readonly color: Role | null;
public readonly highest: Role;
public readonly premiumSubscriberRole?: Role;
public member: GuildMember;
public guild: Guild;

Expand Down Expand Up @@ -1955,6 +1959,8 @@ declare module 'discord.js' {
public readonly everyone: Role;
public readonly highest: Role;
public guild: Guild;
public readonly myRole?: Role;
public readonly premiumSubscriberRole?: Role;
almostSouji marked this conversation as resolved.
Show resolved Hide resolved

public create(options?: { data?: RoleData; reason?: string }): Promise<Role>;
public fetch(id: Snowflake, cache?: boolean): Promise<Role | null>;
Expand Down Expand Up @@ -2962,6 +2968,12 @@ declare module 'discord.js' {

type RoleResolvable = Role | string;

interface RoleTagData {
botID?: Snowflake;
integrationID?: Snowflake;
premiumSubcriberRole?: boolean;
almostSouji marked this conversation as resolved.
Show resolved Hide resolved
}

type ShardingManagerMode = 'process' | 'worker';

type Snowflake = string;
Expand Down