UNPKG

darkcord

Version:

A NodeJS Package to interact with Discord API

146 lines (145 loc) 3.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Role = void 0; const Constants_1 = require("../utils/Constants"); const Base_1 = require("./Base"); const Permission_1 = require("./Permission"); class Role extends Base_1.Base { guild; /** * Role name */ name; /** * Integer representation of hexadecimal color code */ color; /** * If this role is pinned in the user listing */ hoist; /** * Role icon hash */ icon; /** * Role unicode emoji */ unicodeEmoji; /** * Position of this role */ position; /** * Permission bit set */ permissions; /** * Whether this role is managed by an integration */ managed; /** * Whether this role is mentionable */ mentionable; /** * The tags this role has */ tags; constructor(data, guild) { super(data); this.guild = guild; this._update(data); } _update(data) { if ("name" in data) this.name = data.name; if ("color" in data) this.color = data.color; if ("hoist" in data) this.hoist = Boolean(data.hoist); else this.hoist ??= false; if ("icon" in data) this.icon = data.icon; if ("position" in data) this.position = data.position; if ("mentionable" in data) this.mentionable = Boolean(data.mentionable); else this.mentionable ??= false; if ("tags" in data) this.tags = data.tags; if ("permissions" in data) this.permissions = new Permission_1.Permissions(BigInt(data.permissions)); if ("managed" in data) this.managed = Boolean(data.managed); else this.managed ??= false; if ("unicode_emoji" in data) this.unicodeEmoji = data.unicode_emoji; this.rawData = Object.assign({}, data, this.rawData); return this; } /** * Compare the position of the current role with another role * @param roleId The role id to compare with * @returns */ comparePositionTo(roleId) { return this.guild.roles.comparePositions(this.id, roleId); } /** * Modify the position of this role * @param newPosition The new position of the role * @param reason The reason for modifying the position * @returns */ setPosition(newPosition, reason) { return this.guild.setRolePosition(this.id, newPosition, reason); } /** * Edit this role * @param options The options to edit this role * @param reason The reason for editing this role * @returns */ edit(options, reason) { return this.guild.editRole(this.id, options, reason); } /** * Update information of this role * * Util if this is forged * @returns */ async fetchInformation() { const data = await this._client.rest.getRoles(this.id); return this._update(data.find((r) => r.id === this.id) ?? {}); } get forged() { return Boolean(this.id && !this.color && !this.name); } toString() { return (0, Constants_1.roleMention)(this.id); } toJSON() { return Base_1.Base.toJSON(this, [ "color", "createdAt", "guild", "hoist", "icon", "id", "managed", "mentionable", "name", "permissions", "position", "rawData", "tags", "unicodeEmoji", ]); } } exports.Role = Role;