summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/managers/GuildEmojiRoleManager.js
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-30 15:46:16 -0700
committer8cy <[email protected]>2020-04-30 15:46:16 -0700
commit3a4deac89054021b56ad5bd8005b2044cc085c98 (patch)
tree3dd6af8503e497e46180b6b5231674f36bdce9f2 /node_modules/discord.js/src/managers/GuildEmojiRoleManager.js
downloaduppity-3a4deac89054021b56ad5bd8005b2044cc085c98.tar.xz
uppity-3a4deac89054021b56ad5bd8005b2044cc085c98.zip
Up, up, uppity.
Diffstat (limited to 'node_modules/discord.js/src/managers/GuildEmojiRoleManager.js')
-rw-r--r--node_modules/discord.js/src/managers/GuildEmojiRoleManager.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/managers/GuildEmojiRoleManager.js b/node_modules/discord.js/src/managers/GuildEmojiRoleManager.js
new file mode 100644
index 0000000..038571f
--- /dev/null
+++ b/node_modules/discord.js/src/managers/GuildEmojiRoleManager.js
@@ -0,0 +1,119 @@
+'use strict';
+
+const { TypeError } = require('../errors');
+const Collection = require('../util/Collection');
+
+/**
+ * Manages API methods for roles belonging to emojis and stores their cache.
+ */
+class GuildEmojiRoleManager {
+ constructor(emoji) {
+ /**
+ * The emoji belonging to this manager
+ * @type {GuildEmoji}
+ */
+ this.emoji = emoji;
+ /**
+ * The guild belonging to this manager
+ * @type {Guild}
+ */
+ this.guild = emoji.guild;
+ /**
+ * The client belonging to this manager
+ * @type {Client}
+ * @readonly
+ */
+ Object.defineProperty(this, 'client', { value: emoji.client });
+ }
+
+ /**
+ * The filtered collection of roles of the guild emoji
+ * @type {Collection<Snowflake, Role>}
+ * @private
+ * @readonly
+ */
+ get _roles() {
+ return this.guild.roles.cache.filter(role => this.emoji._roles.includes(role.id));
+ }
+
+ /**
+ * The cache of roles belonging to this emoji
+ * @type {Collection<Snowflake, Role>}
+ * @readonly
+ */
+ get cache() {
+ return this._roles;
+ }
+
+ /**
+ * Adds a role (or multiple roles) to the list of roles that can use this emoji.
+ * @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to add
+ * @returns {Promise<GuildEmoji>}
+ */
+ add(roleOrRoles) {
+ if (roleOrRoles instanceof Collection) return this.add(roleOrRoles.keyArray());
+ if (!Array.isArray(roleOrRoles)) return this.add([roleOrRoles]);
+ roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
+
+ if (roleOrRoles.includes(null)) {
+ return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true));
+ }
+
+ const newRoles = [...new Set(roleOrRoles.concat(...this._roles.values()))];
+ return this.set(newRoles);
+ }
+
+ /**
+ * Removes a role (or multiple roles) from the list of roles that can use this emoji.
+ * @param {RoleResolvable|RoleResolvable[]|Collection<Snowflake, Role>} roleOrRoles The role or roles to remove
+ * @returns {Promise<GuildEmoji>}
+ */
+ remove(roleOrRoles) {
+ if (roleOrRoles instanceof Collection) return this.remove(roleOrRoles.keyArray());
+ if (!Array.isArray(roleOrRoles)) return this.remove([roleOrRoles]);
+ roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolveID(r));
+
+ if (roleOrRoles.includes(null)) {
+ return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true));
+ }
+
+ const newRoles = this._roles.keyArray().filter(role => !roleOrRoles.includes(role));
+ return this.set(newRoles);
+ }
+
+ /**
+ * Sets the role(s) that can use this emoji.
+ * @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role IDs to apply
+ * @returns {Promise<GuildEmoji>}
+ * @example
+ * // Set the emoji's roles to a single role
+ * guildEmoji.roles.set(['391156570408615936'])
+ * .then(console.log)
+ * .catch(console.error);
+ * @example
+ * // Remove all roles from an emoji
+ * guildEmoji.roles.set([])
+ * .then(console.log)
+ * .catch(console.error);
+ */
+ set(roles) {
+ return this.emoji.edit({ roles });
+ }
+
+ clone() {
+ const clone = new this.constructor(this.emoji);
+ clone._patch(this._roles.keyArray().slice());
+ return clone;
+ }
+
+ /**
+ * Patches the roles for this manager's cache
+ * @param {Snowflake[]} roles The new roles
+ * @private
+ */
+ _patch(roles) {
+ this.emoji._roles = roles;
+ }
+}
+
+module.exports = GuildEmojiRoleManager;