Skip to content

Commit

Permalink
refactor(GuildPreviewEmoji): make roles an array (#5720)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaporoxx authored Jun 13, 2021
1 parent 02693bc commit 4dbcaf7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
10 changes: 0 additions & 10 deletions src/structures/BaseGuildEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ class BaseGuildEmoji extends Emoji {
this.managed = null;
this.available = null;

/**
* Array of role ids this emoji is active for
* @name BaseGuildEmoji#_roles
* @type {Snowflake[]}
* @private
*/
Object.defineProperty(this, '_roles', { value: [], writable: true });

this._patch(data);
}

Expand Down Expand Up @@ -58,8 +50,6 @@ class BaseGuildEmoji extends Emoji {
*/
this.available = data.available;
}

if (data.roles) this._roles = data.roles;
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/structures/GuildEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class GuildEmoji extends BaseGuildEmoji {
* @type {?User}
*/
this.author = null;

/**
* Array of role ids this emoji is active for
* @name GuildEmoji#_roles
* @type {Snowflake[]}
* @private
*/
Object.defineProperty(this, '_roles', { value: [], writable: true });
}

/**
Expand All @@ -39,7 +47,9 @@ class GuildEmoji extends BaseGuildEmoji {

_patch(data) {
super._patch(data);
if (typeof data.user !== 'undefined') this.author = this.client.users.add(data.user);

if (data.user) this.author = this.client.users.add(data.user);
if (data.roles) this._roles = data.roles;
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/structures/GuildPreviewEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class GuildPreviewEmoji extends BaseGuildEmoji {
* @name GuildPreviewEmoji#guild
*/

/**
* Set of roles this emoji is active for
* @type {Set<Snowflake>}
* @readonly
*/
get roles() {
return new Set(this._roles);
constructor(client, data, guild) {
super(client, data, guild);

/**
* The roles this emoji is active for
* @type {Snowflake[]}
*/
this.roles = data.roles;
}
}

Expand Down
9 changes: 5 additions & 4 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ declare module 'discord.js' {
}

export class BaseGuildEmoji extends Emoji {
constructor(client: Client, data: unknown, guild: Guild);
private _roles: Snowflake[];

constructor(client: Client, data: unknown, guild: Guild | GuildPreview);
public available: boolean | null;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
Expand Down Expand Up @@ -924,6 +922,9 @@ declare module 'discord.js' {
}

export class GuildEmoji extends BaseGuildEmoji {
constructor(client: Client, data: unknown, guild: Guild);
private _roles: Snowflake[];

public readonly deletable: boolean;
public guild: Guild;
public author: User | null;
Expand Down Expand Up @@ -1020,7 +1021,7 @@ declare module 'discord.js' {
export class GuildPreviewEmoji extends BaseGuildEmoji {
constructor(client: Client, data: unknown, guild: GuildPreview);
public guild: GuildPreview;
public readonly roles: Set<Snowflake>;
public roles: Snowflake[];
}

export class HTTPError extends Error {
Expand Down

0 comments on commit 4dbcaf7

Please sign in to comment.