diff --git a/discord.11.4-dev.js b/discord.11.4-dev.js index 3f19b30f..f331d200 100644 --- a/discord.11.4-dev.js +++ b/discord.11.4-dev.js @@ -1492,7 +1492,7 @@ eval("const Channel = __webpack_require__(/*! ./Channel */ \"./src/structures/Ch /*! ModuleConcatenation bailout: Module is not an ECMAScript module */ /***/ (function(module, exports, __webpack_require__) { -eval("const Constants = __webpack_require__(/*! ../util/Constants */ \"./src/util/Constants.js\");\nconst Collection = __webpack_require__(/*! ../util/Collection */ \"./src/util/Collection.js\");\nconst Permissions = __webpack_require__(/*! ../util/Permissions */ \"./src/util/Permissions.js\");\nconst Snowflake = __webpack_require__(/*! ../util/Snowflake */ \"./src/util/Snowflake.js\");\n\n/**\n * Represents a custom emoji.\n */\nclass Emoji {\n constructor(guild, data) {\n /**\n * The client that instantiated this object\n * @name Emoji#client\n * @type {Client}\n * @readonly\n */\n Object.defineProperty(this, 'client', { value: guild.client });\n\n /**\n * The guild this emoji is part of\n * @type {Guild}\n */\n this.guild = guild;\n\n /**\n * Whether this emoji has been deleted\n * @type {boolean}\n */\n this.deleted = false;\n\n this.setup(data);\n }\n\n setup(data) {\n /**\n * The ID of the emoji\n * @type {Snowflake}\n */\n this.id = data.id;\n\n /**\n * The name of the emoji\n * @type {string}\n */\n this.name = data.name;\n\n /**\n * Whether or not this emoji requires colons surrounding it\n * @type {boolean}\n */\n this.requiresColons = data.require_colons;\n\n /**\n * Whether this emoji is managed by an external service\n * @type {boolean}\n */\n this.managed = data.managed;\n\n /**\n * Whether this emoji is animated\n * @type {boolean}\n */\n this.animated = data.animated;\n\n this._roles = data.roles;\n }\n\n /**\n * The timestamp the emoji was created at\n * @type {number}\n * @readonly\n */\n get createdTimestamp() {\n return Snowflake.deconstruct(this.id).timestamp;\n }\n\n /**\n * The time the emoji was created\n * @type {Date}\n * @readonly\n */\n get createdAt() {\n return new Date(this.createdTimestamp);\n }\n\n /**\n * Whether the moej is deletable by the client user\n * @type {boolean}\n * @readonly\n */\n get deletable() {\n return !this.managed && this.guild.me.hasPermission(Permissions.FLAGS.MANAGE_EMOJIS);\n }\n\n /**\n * A collection of roles this emoji is active for (empty if all), mapped by role ID\n * @type {Collection}\n * @readonly\n */\n get roles() {\n const roles = new Collection();\n for (const role of this._roles) {\n if (this.guild.roles.has(role)) roles.set(role, this.guild.roles.get(role));\n }\n return roles;\n }\n\n /**\n * The URL to the emoji file\n * @type {string}\n * @readonly\n */\n get url() {\n return Constants.Endpoints.CDN(this.client.options.http.cdn).Emoji(this.id, this.animated ? 'gif' : 'png');\n }\n\n /**\n * The identifier of this emoji, used for message reactions\n * @type {string}\n * @readonly\n */\n get identifier() {\n if (this.id) return `${this.name}:${this.id}`;\n return encodeURIComponent(this.name);\n }\n\n /**\n * Data for editing an emoji.\n * @typedef {Object} EmojiEditData\n * @property {string} [name] The name of the emoji\n * @property {Collection|Array} [roles] Roles to restrict emoji to\n */\n\n /**\n * Edits the emoji.\n * @param {EmojiEditData} data The new data for the emoji\n * @param {string} [reason] Reason for editing this emoji\n * @returns {Promise}\n * @example\n * // Edit an emoji\n * emoji.edit({name: 'newemoji'})\n * .then(e => console.log(`Edited emoji ${e}`))\n * .catch(console.error);\n */\n edit(data, reason) {\n return this.client.rest.methods.updateEmoji(this, data, reason);\n }\n\n /**\n * Set the name of the emoji.\n * @param {string} name The new name for the emoji\n * @param {string} [reason] The reason for changing the emoji's name\n * @returns {Promise}\n */\n setName(name, reason) {\n return this.edit({ name }, reason);\n }\n\n /**\n * Fetches the author for this emoji\n * @returns {Promise}\n */\n fetchAuthor() {\n if (this.managed) return Promise.reject(new Error('Emoji is managed and has no Author.'));\n return this.client.rest.makeRequest('get', Constants.Endpoints.Guild(this.guild).Emoji(this.id), true)\n .then(emoji => this.client.dataManager.newUser(emoji.user));\n }\n\n /**\n * Add a role to the list of roles that can use this emoji.\n * @param {Role} role The role to add\n * @returns {Promise}\n */\n addRestrictedRole(role) {\n return this.addRestrictedRoles([role]);\n }\n\n /**\n * Add multiple roles to the list of roles that can use this emoji.\n * @param {Role[]} roles Roles to add\n * @returns {Promise}\n */\n addRestrictedRoles(roles) {\n const newRoles = new Collection(this.roles);\n for (const role of roles) {\n if (this.guild.roles.has(role.id)) newRoles.set(role.id, role);\n }\n return this.edit({ roles: newRoles });\n }\n\n /**\n * Remove a role from the list of roles that can use this emoji.\n * @param {Role} role The role to remove\n * @returns {Promise}\n */\n removeRestrictedRole(role) {\n return this.removeRestrictedRoles([role]);\n }\n\n /**\n * Remove multiple roles from the list of roles that can use this emoji.\n * @param {Role[]} roles Roles to remove\n * @returns {Promise}\n */\n removeRestrictedRoles(roles) {\n const newRoles = new Collection(this.roles);\n for (const role of roles) {\n if (newRoles.has(role.id)) newRoles.delete(role.id);\n }\n return this.edit({ roles: newRoles });\n }\n\n /**\n * When concatenated with a string, this automatically returns the emoji mention rather than the object.\n * @returns {string}\n * @example\n * // Send an emoji:\n * const emoji = guild.emojis.first();\n * msg.reply(`Hello! ${emoji}`);\n */\n toString() {\n if (!this.id || !this.requiresColons) {\n return this.name;\n }\n\n return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>`;\n }\n\n /**\n * Whether this emoji is the same as another one.\n * @param {Emoji|Object} other The emoji to compare it to\n * @returns {boolean} Whether the emoji is equal to the given emoji or not\n */\n equals(other) {\n if (other instanceof Emoji) {\n return (\n other.id === this.id &&\n other.name === this.name &&\n other.managed === this.managed &&\n other.requiresColons === this.requiresColons\n );\n } else {\n return (\n other.id === this.id &&\n other.name === this.name\n );\n }\n }\n}\n\nmodule.exports = Emoji;\n\n\n//# sourceURL=webpack:///./src/structures/Emoji.js?"); +eval("const Constants = __webpack_require__(/*! ../util/Constants */ \"./src/util/Constants.js\");\nconst Collection = __webpack_require__(/*! ../util/Collection */ \"./src/util/Collection.js\");\nconst Permissions = __webpack_require__(/*! ../util/Permissions */ \"./src/util/Permissions.js\");\nconst Snowflake = __webpack_require__(/*! ../util/Snowflake */ \"./src/util/Snowflake.js\");\n\n/**\n * Represents a custom emoji.\n */\nclass Emoji {\n constructor(guild, data) {\n /**\n * The client that instantiated this object\n * @name Emoji#client\n * @type {Client}\n * @readonly\n */\n Object.defineProperty(this, 'client', { value: guild.client });\n\n /**\n * The guild this emoji is part of\n * @type {Guild}\n */\n this.guild = guild;\n\n /**\n * Whether this emoji has been deleted\n * @type {boolean}\n */\n this.deleted = false;\n\n this.setup(data);\n }\n\n setup(data) {\n /**\n * The ID of the emoji\n * @type {Snowflake}\n */\n this.id = data.id;\n\n /**\n * The name of the emoji\n * @type {string}\n */\n this.name = data.name;\n\n /**\n * Whether or not this emoji requires colons surrounding it\n * @type {boolean}\n */\n this.requiresColons = data.require_colons;\n\n /**\n * Whether this emoji is managed by an external service\n * @type {boolean}\n */\n this.managed = data.managed;\n\n /**\n * Whether this emoji is animated\n * @type {boolean}\n */\n this.animated = data.animated;\n\n this._roles = data.roles;\n }\n\n /**\n * The timestamp the emoji was created at\n * @type {number}\n * @readonly\n */\n get createdTimestamp() {\n return Snowflake.deconstruct(this.id).timestamp;\n }\n\n /**\n * The time the emoji was created\n * @type {Date}\n * @readonly\n */\n get createdAt() {\n return new Date(this.createdTimestamp);\n }\n\n /**\n * Whether the emoji is deletable by the client user\n * @type {boolean}\n * @readonly\n */\n get deletable() {\n return !this.managed && this.guild.me.hasPermission(Permissions.FLAGS.MANAGE_EMOJIS);\n }\n\n /**\n * A collection of roles this emoji is active for (empty if all), mapped by role ID\n * @type {Collection}\n * @readonly\n */\n get roles() {\n const roles = new Collection();\n for (const role of this._roles) {\n if (this.guild.roles.has(role)) roles.set(role, this.guild.roles.get(role));\n }\n return roles;\n }\n\n /**\n * The URL to the emoji file\n * @type {string}\n * @readonly\n */\n get url() {\n return Constants.Endpoints.CDN(this.client.options.http.cdn).Emoji(this.id, this.animated ? 'gif' : 'png');\n }\n\n /**\n * The identifier of this emoji, used for message reactions\n * @type {string}\n * @readonly\n */\n get identifier() {\n if (this.id) return `${this.name}:${this.id}`;\n return encodeURIComponent(this.name);\n }\n\n /**\n * Data for editing an emoji.\n * @typedef {Object} EmojiEditData\n * @property {string} [name] The name of the emoji\n * @property {Collection|Array} [roles] Roles to restrict emoji to\n */\n\n /**\n * Edits the emoji.\n * @param {EmojiEditData} data The new data for the emoji\n * @param {string} [reason] Reason for editing this emoji\n * @returns {Promise}\n * @example\n * // Edit an emoji\n * emoji.edit({name: 'newemoji'})\n * .then(e => console.log(`Edited emoji ${e}`))\n * .catch(console.error);\n */\n edit(data, reason) {\n return this.client.rest.methods.updateEmoji(this, data, reason);\n }\n\n /**\n * Set the name of the emoji.\n * @param {string} name The new name for the emoji\n * @param {string} [reason] The reason for changing the emoji's name\n * @returns {Promise}\n */\n setName(name, reason) {\n return this.edit({ name }, reason);\n }\n\n /**\n * Fetches the author for this emoji\n * @returns {Promise}\n */\n fetchAuthor() {\n if (this.managed) return Promise.reject(new Error('Emoji is managed and has no Author.'));\n return this.client.rest.makeRequest('get', Constants.Endpoints.Guild(this.guild).Emoji(this.id), true)\n .then(emoji => this.client.dataManager.newUser(emoji.user));\n }\n\n /**\n * Add a role to the list of roles that can use this emoji.\n * @param {Role} role The role to add\n * @returns {Promise}\n */\n addRestrictedRole(role) {\n return this.addRestrictedRoles([role]);\n }\n\n /**\n * Add multiple roles to the list of roles that can use this emoji.\n * @param {Role[]} roles Roles to add\n * @returns {Promise}\n */\n addRestrictedRoles(roles) {\n const newRoles = new Collection(this.roles);\n for (const role of roles) {\n if (this.guild.roles.has(role.id)) newRoles.set(role.id, role);\n }\n return this.edit({ roles: newRoles });\n }\n\n /**\n * Remove a role from the list of roles that can use this emoji.\n * @param {Role} role The role to remove\n * @returns {Promise}\n */\n removeRestrictedRole(role) {\n return this.removeRestrictedRoles([role]);\n }\n\n /**\n * Remove multiple roles from the list of roles that can use this emoji.\n * @param {Role[]} roles Roles to remove\n * @returns {Promise}\n */\n removeRestrictedRoles(roles) {\n const newRoles = new Collection(this.roles);\n for (const role of roles) {\n if (newRoles.has(role.id)) newRoles.delete(role.id);\n }\n return this.edit({ roles: newRoles });\n }\n\n /**\n * When concatenated with a string, this automatically returns the emoji mention rather than the object.\n * @returns {string}\n * @example\n * // Send an emoji:\n * const emoji = guild.emojis.first();\n * msg.reply(`Hello! ${emoji}`);\n */\n toString() {\n if (!this.id || !this.requiresColons) {\n return this.name;\n }\n\n return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>`;\n }\n\n /**\n * Whether this emoji is the same as another one.\n * @param {Emoji|Object} other The emoji to compare it to\n * @returns {boolean} Whether the emoji is equal to the given emoji or not\n */\n equals(other) {\n if (other instanceof Emoji) {\n return (\n other.id === this.id &&\n other.name === this.name &&\n other.managed === this.managed &&\n other.requiresColons === this.requiresColons\n );\n } else {\n return (\n other.id === this.id &&\n other.name === this.name\n );\n }\n }\n}\n\nmodule.exports = Emoji;\n\n\n//# sourceURL=webpack:///./src/structures/Emoji.js?"); /***/ }),