Permissions.js
5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
'use strict';
const BitField = require('./BitField');
/**
* 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 {
/**
* Bitfield of the packed bits
* @type {bigint}
* @name Permissions#bitfield
*/
/**
* Data that can be resolved to give a permission number. This can be:
* * A string (see {@link Permissions.FLAGS})
* * A permission number
* * An instance of Permissions
* * An Array of PermissionResolvable
* @typedef {string|bigint|Permissions|PermissionResolvable[]} PermissionResolvable
*/
/**
* Gets all given bits that are missing from the bitfield.
* @param {BitFieldResolvable} bits Bit(s) to check for
* @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override
* @returns {string[]}
*/
missing(bits, checkAdmin = true) {
return checkAdmin && this.has(this.constructor.FLAGS.ADMINISTRATOR) ? [] : super.missing(bits);
}
/**
* 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);
}
/**
* Gets an {@link Array} of bitfield names based on the permissions available.
* @returns {string[]}
*/
toArray() {
return super.toArray(false);
}
}
/**
* Numeric permission flags. All available properties:
* * `CREATE_INSTANT_INVITE` (create invitations to the guild)
* * `KICK_MEMBERS`
* * `BAN_MEMBERS`
* * `ADMINISTRATOR` (implicitly has *all* permissions, and bypasses all channel overwrites)
* * `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)
* * `VIEW_GUILD_INSIGHTS`
* * `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_WEBHOOKS`
* * `MANAGE_EMOJIS_AND_STICKERS`
* * `USE_APPLICATION_COMMANDS`
* * `REQUEST_TO_SPEAK`
* * `MANAGE_EVENTS`
* * `MANAGE_THREADS`
* * `USE_PUBLIC_THREADS` (deprecated)
* * `CREATE_PUBLIC_THREADS`
* * `USE_PRIVATE_THREADS` (deprecated)
* * `CREATE_PRIVATE_THREADS`
* * `USE_EXTERNAL_STICKERS` (use stickers from different guilds)
* * `SEND_MESSAGES_IN_THREADS`
* * `START_EMBEDDED_ACTIVITIES`
* * `MODERATE_MEMBERS`
* @type {Object<string, bigint>}
* @see {@link https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags}
*/
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_EVENTS: 1n << 33n,
MANAGE_THREADS: 1n << 34n,
// TODO: Remove deprecated USE_*_THREADS flags in v14
USE_PUBLIC_THREADS: 1n << 35n,
CREATE_PUBLIC_THREADS: 1n << 35n,
USE_PRIVATE_THREADS: 1n << 36n,
CREATE_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 {bigint}
*/
Permissions.ALL = Object.values(Permissions.FLAGS).reduce((all, p) => all | p, 0n);
/**
* Bitfield representing the default permissions for users
* @type {bigint}
*/
Permissions.DEFAULT = BigInt(104324673);
/**
* Bitfield representing the permissions required for moderators of stage channels
* @type {bigint}
*/
Permissions.STAGE_MODERATOR =
Permissions.FLAGS.MANAGE_CHANNELS | Permissions.FLAGS.MUTE_MEMBERS | Permissions.FLAGS.MOVE_MEMBERS;
Permissions.defaultBit = BigInt(0);
module.exports = Permissions;