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:
Pascal
2018-03-16 20:01:43 +01:00
parent acd1740f0b
commit d041cb2460
3 changed files with 24 additions and 10 deletions

View File

@@ -27,11 +27,9 @@ class GuildEmojiRoleStore extends DataStore {
if (roleOrRoles.includes(null)) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true));
} else {
for (const role of roleOrRoles) super.set(role.id, role);
}
return this.set(this);
const newRoles = [...new Set(roleOrRoles.concat(this.array()))];
return this.set(newRoles);
}
/**
@@ -48,11 +46,9 @@ class GuildEmojiRoleStore extends DataStore {
if (roleOrRoles.includes(null)) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true));
} else {
for (const role of roleOrRoles) super.remove(role);
}
return this.set(this);
const newRoles = this.keyArray().filter(role => !roleOrRoles.includes(role));
return this.set(newRoles);
}
/**
@@ -74,6 +70,12 @@ class GuildEmojiRoleStore extends DataStore {
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
* @param {Snowflake[]} roles The new roles