UNPKG

djs-selfbot-v11

Version:

Selfbot module Discord

238 lines (220 loc) 8.36 kB
const BitField = require('./BitField'); const util = require('util'); /** * Data structure that makes it easy to interact with a permission bitfield. All {@link GuildMember}s have a set of * permissions in their guild, and each channel in the guild may also have {@link PermissionOverwrites} for the member * that override their default permissions. * @extends {BitField} */ class Permissions extends BitField { /** * @param {GuildMember} [member] Member the permissions are for **(deprecated)** * @param {number|PermissionResolvable} permissions Permissions or bitfield to read from */ constructor(member, permissions) { super(typeof member === 'object' && !(member instanceof Array) ? permissions : member); Object.defineProperty(this, '_member', { writable: true, value: typeof member === 'object' && !(member instanceof Array) ? member : null, }); } /** * Member the permissions are for * @type {GuildMember} * @deprecated */ get member() { return this._member; } set member(value) { this._member = value; } /** * Bitfield of the packed permissions * @type {number} * @see {@link Permissions#bitfield} * @deprecated * @readonly */ get raw() { return this.bitfield; } set raw(raw) { this.bitfield = raw; } /** * Checks whether the bitfield has a permission, or any of multiple permissions. * @param {PermissionResolvable} permission Permission(s) to check for * @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override * @returns {boolean} */ any(permission, checkAdmin = true) { return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.any(permission); } /** * Checks whether the bitfield has a permission, or multiple permissions. * @param {PermissionResolvable} permission Permission(s) to check for * @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override * @returns {boolean} */ has(permission, checkAdmin = true) { return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.has(permission); } /** * Checks whether the user has a certain permission, e.g. `READ_MESSAGES`. * @param {PermissionResolvable} permission The permission to check for * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permission * @returns {boolean} * @see {@link Permissions#has} * @deprecated */ hasPermission(permission, explicit = false) { return this.has(permission, !explicit); } /** * Checks whether the user has all specified permissions. * @param {PermissionResolvable} permissions The permissions to check for * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permissions * @returns {boolean} * @see {@link Permissions#has} * @deprecated */ hasPermissions(permissions, explicit = false) { return this.has(permissions, !explicit); } /** * Checks whether the user has all specified permissions, and lists any missing permissions. * @param {PermissionResolvable} permissions The permissions to check for * @param {boolean} [explicit=false] Whether to require the user to explicitly have the exact permissions * @returns {PermissionResolvable} * @see {@link Permissions#missing} * @deprecated */ missingPermissions(permissions, explicit = false) { return this.missing(permissions, !explicit); } } /** * Data that can be resolved to give a permission number. This can be: * * A string (see {@link Permissions.FLAGS}) * * A permission number * @typedef {string|number|Permissions|PermissionResolvable[]} PermissionResolvable */ /** * Numeric permission flags. All available properties: * - `ADMINISTRATOR` (implicitly has *all* permissions, and bypasses all channel overwrites) * - `CREATE_INSTANT_INVITE` (create invitations to the guild) * - `KICK_MEMBERS` * - `BAN_MEMBERS` * - `MANAGE_CHANNELS` (edit and reorder channels) * - `MANAGE_GUILD` (edit the guild information, region, etc.) * - `ADD_REACTIONS` (add new reactions to messages) * - `VIEW_AUDIT_LOG` * - `PRIORITY_SPEAKER` * - `STREAM` * - `VIEW_CHANNEL` * - `SEND_MESSAGES` * - `SEND_TTS_MESSAGES` * - `MANAGE_MESSAGES` (delete messages and reactions) * - `EMBED_LINKS` (links posted will have a preview embedded) * - `ATTACH_FILES` * - `READ_MESSAGE_HISTORY` (view messages that were posted prior to opening Discord) * - `MENTION_EVERYONE` * - `USE_EXTERNAL_EMOJIS` (use emojis from different guilds) * - `EXTERNAL_EMOJIS` **(deprecated)** * - `CONNECT` (connect to a voice channel) * - `SPEAK` (speak in a voice channel) * - `MUTE_MEMBERS` (mute members across all voice channels) * - `DEAFEN_MEMBERS` (deafen members across all voice channels) * - `MOVE_MEMBERS` (move members between voice channels) * - `USE_VAD` (use voice activity detection) * - `CHANGE_NICKNAME` * - `MANAGE_NICKNAMES` (change other members' nicknames) * - `MANAGE_ROLES` * - `MANAGE_ROLES_OR_PERMISSIONS` **(deprecated)** * - `MANAGE_WEBHOOKS` * - `MANAGE_EMOJIS` * @type {Object} * @see {@link https://discordapp.com/developers/docs/topics/permissions} */ Permissions.FLAGS = { CREATE_INSTANT_INVITE: 1n << 0n, KICK_MEMBERS: 1n << 1n, BAN_MEMBERS: 1n << 2n, ADMINISTRATOR: 1n << 3n, MANAGE_CHANNELS: 1n << 4n, MANAGE_GUILD: 1n << 5n, ADD_REACTIONS: 1n << 6n, VIEW_AUDIT_LOG: 1n << 7n, PRIORITY_SPEAKER: 1n << 8n, STREAM: 1n << 9n, VIEW_CHANNEL: 1n << 10n, SEND_MESSAGES: 1n << 11n, SEND_TTS_MESSAGES: 1n << 12n, MANAGE_MESSAGES: 1n << 13n, EMBED_LINKS: 1n << 14n, ATTACH_FILES: 1n << 15n, READ_MESSAGE_HISTORY: 1n << 16n, MENTION_EVERYONE: 1n << 17n, USE_EXTERNAL_EMOJIS: 1n << 18n, VIEW_GUILD_INSIGHTS: 1n << 19n, CONNECT: 1n << 20n, SPEAK: 1n << 21n, MUTE_MEMBERS: 1n << 22n, DEAFEN_MEMBERS: 1n << 23n, MOVE_MEMBERS: 1n << 24n, USE_VAD: 1n << 25n, CHANGE_NICKNAME: 1n << 26n, MANAGE_NICKNAMES: 1n << 27n, MANAGE_ROLES: 1n << 28n, MANAGE_WEBHOOKS: 1n << 29n, MANAGE_EMOJIS_AND_STICKERS: 1n << 30n, USE_APPLICATION_COMMANDS: 1n << 31n, REQUEST_TO_SPEAK: 1n << 32n, MANAGE_THREADS: 1n << 34n, USE_PUBLIC_THREADS: 1n << 35n, USE_PRIVATE_THREADS: 1n << 36n, USE_EXTERNAL_STICKERS: 1n << 37n, SEND_MESSAGES_IN_THREADS: 1n << 38n, START_EMBEDDED_ACTIVITIES: 1n << 39n, MODERATE_MEMBERS: 1n << 40n }; /** * Bitfield representing every permission combined * @type {number} */ Permissions.ALL = Object.keys(Permissions.FLAGS).reduce((all, p) => all | Permissions.FLAGS[p], 0n); /** * Bitfield representing the default permissions for users * @type {number} */ Permissions.DEFAULT = BigInt(104324673); Permissions.defaultBit = BigInt(0); /** * @class EvaluatedPermissions * @classdesc The final evaluated permissions for a member in a channel * @see {@link Permissions} * @deprecated */ Permissions.prototype.hasPermission = util.deprecate(Permissions.prototype.hasPermission, 'EvaluatedPermissions#hasPermission is deprecated, use Permissions#has instead'); Permissions.prototype.hasPermissions = util.deprecate(Permissions.prototype.hasPermissions, 'EvaluatedPermissions#hasPermissions is deprecated, use Permissions#has instead'); Permissions.prototype.missingPermissions = util.deprecate(Permissions.prototype.missingPermissions, 'EvaluatedPermissions#missingPermissions is deprecated, use Permissions#missing instead'); Object.defineProperty(Permissions.prototype, 'raw', { get: util .deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'raw').get, 'EvaluatedPermissions#raw is deprecated use Permissions#bitfield instead'), set: util.deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'raw').set, 'EvaluatedPermissions#raw is deprecated use Permissions#bitfield instead'), }); Object.defineProperty(Permissions.prototype, 'member', { get: util .deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'member').get, 'EvaluatedPermissions#member is deprecated'), set: util .deprecate(Object.getOwnPropertyDescriptor(Permissions.prototype, 'member').set, 'EvaluatedPermissions#member is deprecated'), }); module.exports = Permissions;