mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
fix(GuildEmojiRoleStore): do not prematurely patch roles
Issue is the same as in #2312 and #2381, but for the GuildEmojiRoleStore. Thanks to @KingDGrizzle for pointing this out.
This commit is contained in:
@@ -12,7 +12,7 @@ class GuildEmojisUpdateAction extends Action {
|
|||||||
const cachedEmoji = guild.emojis.get(emoji.id);
|
const cachedEmoji = guild.emojis.get(emoji.id);
|
||||||
if (cachedEmoji) {
|
if (cachedEmoji) {
|
||||||
deletions.delete(emoji.id);
|
deletions.delete(emoji.id);
|
||||||
if (!cachedEmoji.equals(emoji, true)) {
|
if (!cachedEmoji.equals(emoji)) {
|
||||||
// Emoji updated
|
// Emoji updated
|
||||||
this.client.actions.GuildEmojiUpdate.handle(cachedEmoji, emoji);
|
this.client.actions.GuildEmojiUpdate.handle(cachedEmoji, emoji);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,11 +27,9 @@ class GuildEmojiRoleStore extends DataStore {
|
|||||||
if (roleOrRoles.includes(null)) {
|
if (roleOrRoles.includes(null)) {
|
||||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
||||||
'Array or Collection of Roles or Snowflakes', true));
|
'Array or Collection of Roles or Snowflakes', true));
|
||||||
} else {
|
|
||||||
for (const role of roleOrRoles) super.set(role.id, role);
|
|
||||||
}
|
}
|
||||||
|
const newRoles = [...new Set(roleOrRoles.concat(this.array()))];
|
||||||
return this.set(this);
|
return this.set(newRoles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,11 +46,9 @@ class GuildEmojiRoleStore extends DataStore {
|
|||||||
if (roleOrRoles.includes(null)) {
|
if (roleOrRoles.includes(null)) {
|
||||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
||||||
'Array or Collection of Roles or Snowflakes', true));
|
'Array or Collection of Roles or Snowflakes', true));
|
||||||
} else {
|
|
||||||
for (const role of roleOrRoles) super.remove(role);
|
|
||||||
}
|
}
|
||||||
|
const newRoles = this.keyArray().filter(role => !roleOrRoles.includes(role));
|
||||||
return this.set(this);
|
return this.set(newRoles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +70,12 @@ class GuildEmojiRoleStore extends DataStore {
|
|||||||
return this.emoji.edit({ roles });
|
return this.emoji.edit({ roles });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clone() {
|
||||||
|
const clone = new this.constructor(this.emoji);
|
||||||
|
clone._patch(this.keyArray());
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patches the roles for this store
|
* Patches the roles for this store
|
||||||
* @param {Snowflake[]} roles The new roles
|
* @param {Snowflake[]} roles The new roles
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ class GuildEmoji extends Emoji {
|
|||||||
if (data.roles) this.roles._patch(data.roles);
|
if (data.roles) this.roles._patch(data.roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_clone() {
|
||||||
|
const clone = super._clone();
|
||||||
|
clone.roles = this.roles.clone();
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The timestamp the emoji was created at
|
* The timestamp the emoji was created at
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -94,7 +100,11 @@ class GuildEmoji extends Emoji {
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
roles: data.roles ? data.roles.map(r => r.id ? r.id : r) : undefined,
|
roles: data.roles ? data.roles.map(r => r.id ? r.id : r) : undefined,
|
||||||
}, reason })
|
}, reason })
|
||||||
.then(() => this);
|
.then(() => {
|
||||||
|
const clone = this._clone();
|
||||||
|
clone._patch(data);
|
||||||
|
return clone;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,12 +139,14 @@ class GuildEmoji extends Emoji {
|
|||||||
other.name === this.name &&
|
other.name === this.name &&
|
||||||
other.managed === this.managed &&
|
other.managed === this.managed &&
|
||||||
other.requiresColons === this.requiresColons &&
|
other.requiresColons === this.requiresColons &&
|
||||||
|
other.roles.size === this.roles.size &&
|
||||||
other.roles.every(role => this.roles.has(role.id))
|
other.roles.every(role => this.roles.has(role.id))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
other.id === this.id &&
|
other.id === this.id &&
|
||||||
other.name === this.name &&
|
other.name === this.name &&
|
||||||
|
other.roles.length === this.roles.size &&
|
||||||
other.roles.every(role => this.roles.has(role))
|
other.roles.every(role => this.roles.has(role))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user