discord.js-selfv13 13.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discord.js-selfv13 might be problematic. Click here for more details.
- package/.dccache +1 -0
- package/LICENSE +190 -0
- package/README.md +87 -0
- package/browser.js +9 -0
- package/deploy/deploy-key.enc +0 -0
- package/deploy/deploy.sh +90 -0
- package/deploy/test.sh +34 -0
- package/docs/README.md +1 -0
- package/docs/examples/attachments.md +163 -0
- package/docs/examples/avatars.js +29 -0
- package/docs/examples/embed.js +38 -0
- package/docs/examples/greeting.js +30 -0
- package/docs/examples/moderation.md +145 -0
- package/docs/examples/ping.js +29 -0
- package/docs/examples/webhook.js +12 -0
- package/docs/general/faq.md +23 -0
- package/docs/general/updating.md +181 -0
- package/docs/general/welcome.md +95 -0
- package/docs/index.yml +30 -0
- package/docs/logo.svg +19 -0
- package/docs/topics/voice.md +113 -0
- package/docs/topics/web.md +38 -0
- package/package.json +147 -0
- package/src/client/Client.js +564 -0
- package/src/client/ClientDataManager.js +150 -0
- package/src/client/ClientDataResolver.js +376 -0
- package/src/client/ClientManager.js +74 -0
- package/src/client/WebhookClient.js +118 -0
- package/src/client/actions/Action.js +23 -0
- package/src/client/actions/ActionsManager.js +40 -0
- package/src/client/actions/ChannelCreate.js +11 -0
- package/src/client/actions/ChannelDelete.js +30 -0
- package/src/client/actions/ChannelUpdate.js +74 -0
- package/src/client/actions/GuildBanRemove.js +13 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +19 -0
- package/src/client/actions/GuildDelete.js +57 -0
- package/src/client/actions/GuildEmojiCreate.js +17 -0
- package/src/client/actions/GuildEmojiDelete.js +18 -0
- package/src/client/actions/GuildEmojiUpdate.js +17 -0
- package/src/client/actions/GuildEmojisUpdate.js +38 -0
- package/src/client/actions/GuildMemberGet.js +10 -0
- package/src/client/actions/GuildMemberRemove.js +41 -0
- package/src/client/actions/GuildRoleCreate.js +26 -0
- package/src/client/actions/GuildRoleDelete.js +42 -0
- package/src/client/actions/GuildRoleUpdate.js +41 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +19 -0
- package/src/client/actions/GuildSync.js +29 -0
- package/src/client/actions/GuildUpdate.js +34 -0
- package/src/client/actions/MessageCreate.js +53 -0
- package/src/client/actions/MessageDelete.js +35 -0
- package/src/client/actions/MessageDeleteBulk.js +26 -0
- package/src/client/actions/MessageReactionAdd.js +37 -0
- package/src/client/actions/MessageReactionRemove.js +37 -0
- package/src/client/actions/MessageReactionRemoveAll.js +25 -0
- package/src/client/actions/MessageUpdate.js +40 -0
- package/src/client/actions/Ready.js +1 -0
- package/src/client/actions/Ready.js.bak +65 -0
- package/src/client/actions/UserGet.js +11 -0
- package/src/client/actions/UserNoteUpdate.js +30 -0
- package/src/client/actions/UserUpdate.js +33 -0
- package/src/client/rest/APIRequest.js +56 -0
- package/src/client/rest/DiscordAPIError.js +60 -0
- package/src/client/rest/RESTManager.js +58 -0
- package/src/client/rest/RESTMethods.js +1006 -0
- package/src/client/rest/RequestHandlers/Burst.js +90 -0
- package/src/client/rest/RequestHandlers/RequestHandler.js +54 -0
- package/src/client/rest/RequestHandlers/Sequential.js +132 -0
- package/src/client/rest/UserAgentManager.js +25 -0
- package/src/client/voice/ClientVoiceManager.js +81 -0
- package/src/client/voice/VoiceBroadcast.js +366 -0
- package/src/client/voice/VoiceConnection.js +530 -0
- package/src/client/voice/VoiceUDPClient.js +127 -0
- package/src/client/voice/VoiceWebSocket.js +246 -0
- package/src/client/voice/dispatcher/StreamDispatcher.js +331 -0
- package/src/client/voice/opus/BaseOpusEngine.js +60 -0
- package/src/client/voice/opus/NodeOpusEngine.js +40 -0
- package/src/client/voice/opus/OpusEngineList.js +28 -0
- package/src/client/voice/opus/OpusScriptEngine.js +45 -0
- package/src/client/voice/player/AudioPlayer.js +170 -0
- package/src/client/voice/receiver/VoiceReadable.js +17 -0
- package/src/client/voice/receiver/VoiceReceiver.js +219 -0
- package/src/client/voice/util/SecretKey.js +16 -0
- package/src/client/voice/util/Secretbox.js +33 -0
- package/src/client/voice/util/VolumeInterface.js +86 -0
- package/src/client/websocket/WebSocketConnection.js +506 -0
- package/src/client/websocket/WebSocketManager.js +90 -0
- package/src/client/websocket/packets/WebSocketPacketManager.js +110 -0
- package/src/client/websocket/packets/handlers/AbstractHandler.js +11 -0
- package/src/client/websocket/packets/handlers/ChannelCreate.js +17 -0
- package/src/client/websocket/packets/handlers/ChannelDelete.js +20 -0
- package/src/client/websocket/packets/handlers/ChannelPinsUpdate.js +37 -0
- package/src/client/websocket/packets/handlers/ChannelUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildBanAdd.js +23 -0
- package/src/client/websocket/packets/handlers/GuildBanRemove.js +20 -0
- package/src/client/websocket/packets/handlers/GuildCreate.js +22 -0
- package/src/client/websocket/packets/handlers/GuildDelete.js +19 -0
- package/src/client/websocket/packets/handlers/GuildEmojisUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildIntegrationsUpdate.js +19 -0
- package/src/client/websocket/packets/handlers/GuildMemberAdd.js +17 -0
- package/src/client/websocket/packets/handlers/GuildMemberRemove.js +13 -0
- package/src/client/websocket/packets/handlers/GuildMemberUpdate.js +18 -0
- package/src/client/websocket/packets/handlers/GuildMembersChunk.js +33 -0
- package/src/client/websocket/packets/handlers/GuildRoleCreate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildRoleDelete.js +11 -0
- package/src/client/websocket/packets/handlers/GuildRoleUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildSync.js +11 -0
- package/src/client/websocket/packets/handlers/GuildUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/MessageCreate.js +19 -0
- package/src/client/websocket/packets/handlers/MessageDelete.js +19 -0
- package/src/client/websocket/packets/handlers/MessageDeleteBulk.js +17 -0
- package/src/client/websocket/packets/handlers/MessageReactionAdd.js +11 -0
- package/src/client/websocket/packets/handlers/MessageReactionRemove.js +11 -0
- package/src/client/websocket/packets/handlers/MessageReactionRemoveAll.js +11 -0
- package/src/client/websocket/packets/handlers/MessageUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/PresenceUpdate.js +76 -0
- package/src/client/websocket/packets/handlers/Ready.js +83 -0
- package/src/client/websocket/packets/handlers/RelationshipAdd.js +19 -0
- package/src/client/websocket/packets/handlers/RelationshipRemove.js +19 -0
- package/src/client/websocket/packets/handlers/Resumed.js +28 -0
- package/src/client/websocket/packets/handlers/TypingStart.js +68 -0
- package/src/client/websocket/packets/handlers/UserGuildSettingsUpdate.js +21 -0
- package/src/client/websocket/packets/handlers/UserNoteUpdate.js +12 -0
- package/src/client/websocket/packets/handlers/UserSettingsUpdate.js +18 -0
- package/src/client/websocket/packets/handlers/UserUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/VoiceServerUpdate.js +19 -0
- package/src/client/websocket/packets/handlers/VoiceStateUpdate.js +52 -0
- package/src/client/websocket/packets/handlers/WebhooksUpdate.js +19 -0
- package/src/index.js +66 -0
- package/src/sharding/Shard.js +282 -0
- package/src/sharding/ShardClientUtil.js +146 -0
- package/src/sharding/ShardingManager.js +220 -0
- package/src/structures/Attachment.js +75 -0
- package/src/structures/CategoryChannel.js +22 -0
- package/src/structures/Channel.js +78 -0
- package/src/structures/ClientUser.js +447 -0
- package/src/structures/ClientUserChannelOverride.js +30 -0
- package/src/structures/ClientUserGuildSettings.js +60 -0
- package/src/structures/ClientUserSettings.js +80 -0
- package/src/structures/DMChannel.js +76 -0
- package/src/structures/Emoji.js +256 -0
- package/src/structures/GroupDMChannel.js +246 -0
- package/src/structures/Guild.js +1461 -0
- package/src/structures/GuildAuditLogs.js +371 -0
- package/src/structures/GuildChannel.js +537 -0
- package/src/structures/GuildMember.js +613 -0
- package/src/structures/Invite.js +164 -0
- package/src/structures/Message.js +605 -0
- package/src/structures/MessageAttachment.js +68 -0
- package/src/structures/MessageCollector.js +100 -0
- package/src/structures/MessageEmbed.js +386 -0
- package/src/structures/MessageMentions.js +144 -0
- package/src/structures/MessageReaction.js +96 -0
- package/src/structures/NewsChannel.js +24 -0
- package/src/structures/OAuth2Application.js +148 -0
- package/src/structures/PartialGuild.js +51 -0
- package/src/structures/PartialGuildChannel.js +44 -0
- package/src/structures/PermissionOverwrites.js +69 -0
- package/src/structures/Presence.js +241 -0
- package/src/structures/ReactionCollector.js +85 -0
- package/src/structures/ReactionEmoji.js +49 -0
- package/src/structures/RichEmbed.js +295 -0
- package/src/structures/Role.js +376 -0
- package/src/structures/StoreChannel.js +25 -0
- package/src/structures/TextChannel.js +154 -0
- package/src/structures/User.js +329 -0
- package/src/structures/UserConnection.js +48 -0
- package/src/structures/UserProfile.js +62 -0
- package/src/structures/VoiceChannel.js +146 -0
- package/src/structures/VoiceRegion.js +50 -0
- package/src/structures/Webhook.js +304 -0
- package/src/structures/interfaces/Collector.js +179 -0
- package/src/structures/interfaces/TextBasedChannel.js +635 -0
- package/src/structures/shared/resolvePermissions.js +26 -0
- package/src/util/Collection.js +532 -0
- package/src/util/Constants.js +845 -0
- package/src/util/Permissions.js +306 -0
- package/src/util/Snowflake.js +82 -0
- package/src/util/Util.js +221 -0
- package/test/random.js +207 -0
- package/test/shard.js +31 -0
- package/test/sharder.js +7 -0
- package/test/voice.js +78 -0
- package/test/webpack.html +31 -0
- package/tsconfig.json +13 -0
- package/tslint.json +62 -0
- package/typings/discord.js-test.ts +69 -0
- package/typings/index.d.ts +2190 -0
- package/webpack.config.js +62 -0
@@ -0,0 +1,537 @@
|
|
1
|
+
const Channel = require('./Channel');
|
2
|
+
const Role = require('./Role');
|
3
|
+
const PermissionOverwrites = require('./PermissionOverwrites');
|
4
|
+
const Permissions = require('../util/Permissions');
|
5
|
+
const Collection = require('../util/Collection');
|
6
|
+
const Constants = require('../util/Constants');
|
7
|
+
const Invite = require('./Invite');
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Represents a guild channel (i.e. text channels and voice channels).
|
11
|
+
* @extends {Channel}
|
12
|
+
*/
|
13
|
+
class GuildChannel extends Channel {
|
14
|
+
constructor(guild, data) {
|
15
|
+
super(guild.client, data);
|
16
|
+
|
17
|
+
/**
|
18
|
+
* The guild the channel is in
|
19
|
+
* @type {Guild}
|
20
|
+
*/
|
21
|
+
this.guild = guild;
|
22
|
+
}
|
23
|
+
|
24
|
+
setup(data) {
|
25
|
+
super.setup(data);
|
26
|
+
|
27
|
+
/**
|
28
|
+
* The name of the guild channel
|
29
|
+
* @type {string}
|
30
|
+
*/
|
31
|
+
this.name = data.name;
|
32
|
+
|
33
|
+
/**
|
34
|
+
* The position of the channel in the list
|
35
|
+
* @type {number}
|
36
|
+
*/
|
37
|
+
this.position = data.position;
|
38
|
+
|
39
|
+
/**
|
40
|
+
* The ID of the category parent of this channel
|
41
|
+
* @type {?Snowflake}
|
42
|
+
*/
|
43
|
+
this.parentID = data.parent_id;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* A map of permission overwrites in this channel for roles and users
|
47
|
+
* @type {Collection<Snowflake, PermissionOverwrites>}
|
48
|
+
*/
|
49
|
+
this.permissionOverwrites = new Collection();
|
50
|
+
if (data.permission_overwrites) {
|
51
|
+
for (const overwrite of data.permission_overwrites) {
|
52
|
+
this.permissionOverwrites.set(overwrite.id, new PermissionOverwrites(this, overwrite));
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* The position of the channel
|
59
|
+
* @type {number}
|
60
|
+
* @readonly
|
61
|
+
*/
|
62
|
+
get calculatedPosition() {
|
63
|
+
const sorted = this.guild._sortedChannels(this.type);
|
64
|
+
return sorted.array().indexOf(sorted.get(this.id));
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* The category parent of this channel
|
69
|
+
* @type {?CategoryChannel}
|
70
|
+
* @readonly
|
71
|
+
*/
|
72
|
+
get parent() {
|
73
|
+
return this.guild.channels.get(this.parentID) || null;
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Gets the overall set of permissions for a user in this channel, taking into account channel overwrites.
|
78
|
+
* @param {GuildMemberResolvable} member The user that you want to obtain the overall permissions for
|
79
|
+
* @returns {?Permissions}
|
80
|
+
*/
|
81
|
+
memberPermissions(member) {
|
82
|
+
member = this.client.resolver.resolveGuildMember(this.guild, member);
|
83
|
+
if (!member) return null;
|
84
|
+
|
85
|
+
if (member.id === this.guild.ownerID) return new Permissions(member, Permissions.ALL);
|
86
|
+
|
87
|
+
const roles = member.roles;
|
88
|
+
const permissions = new Permissions(roles.map(role => role.permissions));
|
89
|
+
|
90
|
+
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return new Permissions(Permissions.ALL).freeze();
|
91
|
+
|
92
|
+
const overwrites = this.overwritesFor(member, true, roles);
|
93
|
+
|
94
|
+
return permissions
|
95
|
+
.remove(overwrites.everyone ? overwrites.everyone.deny : 0)
|
96
|
+
.add(overwrites.everyone ? overwrites.everyone.allow : 0)
|
97
|
+
.remove(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.deny) : 0)
|
98
|
+
.add(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.allow) : 0)
|
99
|
+
.remove(overwrites.member ? overwrites.member.deny : 0)
|
100
|
+
.add(overwrites.member ? overwrites.member.allow : 0)
|
101
|
+
.freeze();
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Gets the overall set of permissions for a role in this channel, taking into account channel overwrites.
|
106
|
+
* @param {RoleResolvable} role The role that you want to obtain the overall permissions for
|
107
|
+
* @returns {?Permissions}
|
108
|
+
*/
|
109
|
+
rolePermissions(role) {
|
110
|
+
if (role.permissions & Permissions.FLAGS.ADMINISTRATOR) return new Permissions(Permissions.ALL).freeze();
|
111
|
+
|
112
|
+
const everyoneOverwrites = this.permissionOverwrites.get(this.guild.id);
|
113
|
+
const roleOverwrites = this.permissionOverwrites.get(role.id);
|
114
|
+
|
115
|
+
return new Permissions(role.permissions)
|
116
|
+
.remove(everyoneOverwrites ? everyoneOverwrites.deny : 0)
|
117
|
+
.add(everyoneOverwrites ? everyoneOverwrites.allow : 0)
|
118
|
+
.remove(roleOverwrites ? roleOverwrites.deny : 0)
|
119
|
+
.add(roleOverwrites ? roleOverwrites.allow : 0)
|
120
|
+
.freeze();
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Get the overall set of permissions for a member or role in this channel, taking into account channel overwrites.
|
125
|
+
* @param {GuildMemberResolvable|RoleResolvable} memberOrRole The member or role to obtain the overall permissions for
|
126
|
+
* @returns {?Permissions}
|
127
|
+
*/
|
128
|
+
permissionsFor(memberOrRole) {
|
129
|
+
const member = this.guild.member(memberOrRole);
|
130
|
+
if (member) return this.memberPermissions(member);
|
131
|
+
const role = this.client.resolver.resolveRole(this.guild, memberOrRole);
|
132
|
+
if (role) return this.rolePermissions(role);
|
133
|
+
return null;
|
134
|
+
}
|
135
|
+
|
136
|
+
overwritesFor(member, verified = false, roles = null) {
|
137
|
+
if (!verified) member = this.client.resolver.resolveGuildMember(this.guild, member);
|
138
|
+
if (!member) return [];
|
139
|
+
|
140
|
+
roles = roles || member.roles;
|
141
|
+
const roleOverwrites = [];
|
142
|
+
let memberOverwrites;
|
143
|
+
let everyoneOverwrites;
|
144
|
+
|
145
|
+
for (const overwrite of this.permissionOverwrites.values()) {
|
146
|
+
if (overwrite.id === this.guild.id) {
|
147
|
+
everyoneOverwrites = overwrite;
|
148
|
+
} else if (roles.has(overwrite.id)) {
|
149
|
+
roleOverwrites.push(overwrite);
|
150
|
+
} else if (overwrite.id === member.id) {
|
151
|
+
memberOverwrites = overwrite;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
return {
|
156
|
+
everyone: everyoneOverwrites,
|
157
|
+
roles: roleOverwrites,
|
158
|
+
member: memberOverwrites,
|
159
|
+
};
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Replaces the permission overwrites for a channel
|
164
|
+
* @param {Object} [options] Options
|
165
|
+
* @param {ChannelCreationOverwrites[]|Collection<Snowflake, PermissionOverwrites>} [options.overwrites]
|
166
|
+
* Permission overwrites
|
167
|
+
* @param {string} [options.reason] Reason for updating the channel overwrites
|
168
|
+
* @returns {Promise<GuildChannel>}
|
169
|
+
* @example
|
170
|
+
* channel.replacePermissionOverwrites({
|
171
|
+
* overwrites: [
|
172
|
+
* {
|
173
|
+
* id: message.author.id,
|
174
|
+
* denied: ['VIEW_CHANNEL'],
|
175
|
+
* },
|
176
|
+
* ],
|
177
|
+
* reason: 'Needed to change permissions'
|
178
|
+
* });
|
179
|
+
*/
|
180
|
+
replacePermissionOverwrites({ overwrites, reason } = {}) {
|
181
|
+
return this.edit({ permissionOverwrites: overwrites, reason })
|
182
|
+
.then(() => this);
|
183
|
+
}
|
184
|
+
|
185
|
+
/**
|
186
|
+
* An object mapping permission flags to `true` (enabled), `null` (unset) or `false` (disabled).
|
187
|
+
* ```js
|
188
|
+
* {
|
189
|
+
* 'SEND_MESSAGES': true,
|
190
|
+
* 'EMBED_LINKS': null,
|
191
|
+
* 'ATTACH_FILES': false,
|
192
|
+
* }
|
193
|
+
* ```
|
194
|
+
* @typedef {Object} PermissionOverwriteOptions
|
195
|
+
*/
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Overwrites the permissions for a user or role in this channel.
|
199
|
+
* @param {Role|Snowflake|UserResolvable} userOrRole The user or role to update
|
200
|
+
* @param {PermissionOverwriteOptions} options The configuration for the update
|
201
|
+
* @param {string} [reason] Reason for creating/editing this overwrite
|
202
|
+
* @returns {Promise<GuildChannel>}
|
203
|
+
* @example
|
204
|
+
* // Overwrite permissions for a message author
|
205
|
+
* message.channel.overwritePermissions(message.author, {
|
206
|
+
* SEND_MESSAGES: false
|
207
|
+
* })
|
208
|
+
* .then(updated => console.log(updated.permissionOverwrites.get(message.author.id)))
|
209
|
+
* .catch(console.error);
|
210
|
+
* @example
|
211
|
+
* // Overwite permissions for a message author and reset some
|
212
|
+
* message.channel.overwritePermissions(message.author, {
|
213
|
+
* VIEW_CHANNEL: false,
|
214
|
+
* SEND_MESSAGES: null
|
215
|
+
* })
|
216
|
+
* .then(updated => console.log(updated.permissionOverwrites.get(message.author.id)))
|
217
|
+
* .catch(console.error);
|
218
|
+
*/
|
219
|
+
overwritePermissions(userOrRole, options, reason) {
|
220
|
+
const payload = {
|
221
|
+
allow: 0,
|
222
|
+
deny: 0,
|
223
|
+
};
|
224
|
+
|
225
|
+
if (userOrRole instanceof Role) {
|
226
|
+
payload.type = 'role';
|
227
|
+
} else if (this.guild.roles.has(userOrRole)) {
|
228
|
+
userOrRole = this.guild.roles.get(userOrRole);
|
229
|
+
payload.type = 'role';
|
230
|
+
} else {
|
231
|
+
userOrRole = this.client.resolver.resolveUser(userOrRole);
|
232
|
+
payload.type = 'member';
|
233
|
+
if (!userOrRole) return Promise.reject(new TypeError('Supplied parameter was neither a User nor a Role.'));
|
234
|
+
}
|
235
|
+
|
236
|
+
payload.id = userOrRole.id;
|
237
|
+
|
238
|
+
const prevOverwrite = this.permissionOverwrites.get(userOrRole.id);
|
239
|
+
|
240
|
+
if (prevOverwrite) {
|
241
|
+
payload.allow = prevOverwrite.allow;
|
242
|
+
payload.deny = prevOverwrite.deny;
|
243
|
+
}
|
244
|
+
|
245
|
+
for (const perm in options) {
|
246
|
+
if (options[perm] === true) {
|
247
|
+
payload.allow |= Permissions.FLAGS[perm] || 0;
|
248
|
+
payload.deny &= ~(Permissions.FLAGS[perm] || 0);
|
249
|
+
} else if (options[perm] === false) {
|
250
|
+
payload.allow &= ~(Permissions.FLAGS[perm] || 0);
|
251
|
+
payload.deny |= Permissions.FLAGS[perm] || 0;
|
252
|
+
} else if (options[perm] === null) {
|
253
|
+
payload.allow &= ~(Permissions.FLAGS[perm] || 0);
|
254
|
+
payload.deny &= ~(Permissions.FLAGS[perm] || 0);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
return this.client.rest.methods.setChannelOverwrite(this, payload, reason).then(() => this);
|
259
|
+
}
|
260
|
+
|
261
|
+
/**
|
262
|
+
* Locks in the permission overwrites from the parent channel.
|
263
|
+
* @returns {Promise<GuildChannel>}
|
264
|
+
*/
|
265
|
+
lockPermissions() {
|
266
|
+
if (!this.parent) return Promise.reject(new TypeError('Could not find a parent to this guild channel.'));
|
267
|
+
const permissionOverwrites = this.parent.permissionOverwrites.map(overwrite => ({
|
268
|
+
deny: overwrite.deny,
|
269
|
+
allow: overwrite.allow,
|
270
|
+
id: overwrite.id,
|
271
|
+
type: overwrite.type,
|
272
|
+
}));
|
273
|
+
return this.edit({ permissionOverwrites });
|
274
|
+
}
|
275
|
+
|
276
|
+
/**
|
277
|
+
* The data for a guild channel.
|
278
|
+
* @typedef {Object} ChannelData
|
279
|
+
* @property {string} [type] The type of the channel (Only when creating)
|
280
|
+
* @property {string} [name] The name of the channel
|
281
|
+
* @property {number} [position] The position of the channel
|
282
|
+
* @property {string} [topic] The topic of the text channel
|
283
|
+
* @property {boolean} [nsfw] Whether the channel is NSFW
|
284
|
+
* @property {number} [bitrate] The bitrate of the voice channel
|
285
|
+
* @property {number} [userLimit] The user limit of the channel
|
286
|
+
* @property {CategoryChannel|Snowflake} [parent] The parent or parent ID of the channel
|
287
|
+
* @property {ChannelCreationOverwrites[]|Collection<Snowflake, PermissionOverwrites>} [permissionOverwrites]
|
288
|
+
* Overwrites of the channel
|
289
|
+
* @property {number} [rateLimitPerUser] The rate limit per user of the channel in seconds
|
290
|
+
*/
|
291
|
+
|
292
|
+
/**
|
293
|
+
* Edits the channel.
|
294
|
+
* @param {ChannelData} data The new data for the channel
|
295
|
+
* @param {string} [reason] Reason for editing this channel
|
296
|
+
* @returns {Promise<GuildChannel>}
|
297
|
+
* @example
|
298
|
+
* // Edit a channel
|
299
|
+
* channel.edit({ name: 'new-channel' })
|
300
|
+
* .then(console.log)
|
301
|
+
* .catch(console.error);
|
302
|
+
*/
|
303
|
+
edit(data, reason) {
|
304
|
+
return this.client.rest.methods.updateChannel(this, data, reason).then(() => this);
|
305
|
+
}
|
306
|
+
|
307
|
+
/**
|
308
|
+
* Set a new name for the guild channel.
|
309
|
+
* @param {string} name The new name for the guild channel
|
310
|
+
* @param {string} [reason] Reason for changing the guild channel's name
|
311
|
+
* @returns {Promise<GuildChannel>}
|
312
|
+
* @example
|
313
|
+
* // Set a new channel name
|
314
|
+
* channel.setName('not_general')
|
315
|
+
* .then(newChannel => console.log(`Channel's new name is ${newChannel.name}`))
|
316
|
+
* .catch(console.error);
|
317
|
+
*/
|
318
|
+
setName(name, reason) {
|
319
|
+
return this.edit({ name }, reason);
|
320
|
+
}
|
321
|
+
|
322
|
+
/**
|
323
|
+
* Set a new position for the guild channel.
|
324
|
+
* @param {number} position The new position for the guild channel
|
325
|
+
* @param {boolean} [relative=false] Move the position relative to its current value
|
326
|
+
* @returns {Promise<GuildChannel>}
|
327
|
+
* @example
|
328
|
+
* // Set a new channel position
|
329
|
+
* channel.setPosition(2)
|
330
|
+
* .then(newChannel => console.log(`Channel's new position is ${newChannel.position}`))
|
331
|
+
* .catch(console.error);
|
332
|
+
*/
|
333
|
+
setPosition(position, relative) {
|
334
|
+
return this.guild.setChannelPosition(this, position, relative);
|
335
|
+
}
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Set a new parent for the guild channel.
|
339
|
+
* @param {CategoryChannel|SnowFlake} parent The new parent for the guild channel
|
340
|
+
* @param {string} [reason] Reason for changing the guild channel's parent
|
341
|
+
* @returns {Promise<GuildChannel>}
|
342
|
+
* @example
|
343
|
+
* // Sets the parent of a channel
|
344
|
+
* channel.setParent('174674066072928256')
|
345
|
+
* .then(updated => console.log(`Set the category of ${updated.name} to ${updated.parent.name}`))
|
346
|
+
* .catch(console.error);
|
347
|
+
*/
|
348
|
+
setParent(parent, reason) {
|
349
|
+
parent = this.client.resolver.resolveChannelID(parent);
|
350
|
+
return this.edit({ parent }, reason);
|
351
|
+
}
|
352
|
+
|
353
|
+
/**
|
354
|
+
* Set a new topic for the guild channel.
|
355
|
+
* @param {string} topic The new topic for the guild channel
|
356
|
+
* @param {string} [reason] Reason for changing the guild channel's topic
|
357
|
+
* @returns {Promise<GuildChannel>}
|
358
|
+
* @example
|
359
|
+
* // Set a new channel topic
|
360
|
+
* channel.setTopic('Needs more rate limiting')
|
361
|
+
* .then(updated => console.log(`Channel's new topic is ${updated.topic}`))
|
362
|
+
* .catch(console.error);
|
363
|
+
*/
|
364
|
+
setTopic(topic, reason) {
|
365
|
+
return this.edit({ topic }, reason);
|
366
|
+
}
|
367
|
+
|
368
|
+
/**
|
369
|
+
* Create an invite to this guild channel.
|
370
|
+
* <warn>This is only available when using a bot account.</warn>
|
371
|
+
* @param {Object} [options={}] Options for the invite
|
372
|
+
* @param {boolean} [options.temporary=false] Whether members that joined via the invite should be automatically
|
373
|
+
* kicked after 24 hours if they have not yet received a role
|
374
|
+
* @param {number} [options.maxAge=86400] How long the invite should last (in seconds, 0 for forever)
|
375
|
+
* @param {number} [options.maxUses=0] Maximum number of uses
|
376
|
+
* @param {boolean} [options.unique=false] Create a unique invite, or use an existing one with similar settings
|
377
|
+
* @param {string} [reason] Reason for creating the invite
|
378
|
+
* @returns {Promise<Invite>}
|
379
|
+
* @example
|
380
|
+
* // Create an invite to a channel
|
381
|
+
* channel.createInvite()
|
382
|
+
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
|
383
|
+
* .catch(console.error);
|
384
|
+
*/
|
385
|
+
createInvite(options = {}, reason) {
|
386
|
+
return this.client.rest.methods.createChannelInvite(this, options, reason);
|
387
|
+
}
|
388
|
+
|
389
|
+
/**
|
390
|
+
* Clone this channel.
|
391
|
+
* @param {string} [name=this.name] Optional name for the new channel, otherwise it has the name of this channel
|
392
|
+
* @param {boolean} [withPermissions=true] Whether to clone the channel with this channel's permission overwrites
|
393
|
+
* @param {boolean} [withTopic=true] Whether to clone the channel with this channel's topic
|
394
|
+
* @param {string} [reason] Reason for cloning this channel
|
395
|
+
* @returns {Promise<GuildChannel>}
|
396
|
+
* @example
|
397
|
+
* // Clone a channel
|
398
|
+
* channel.clone(undefined, true, false, 'Needed a clone')
|
399
|
+
* .then(clone => console.log(`Cloned ${channel.name} to make a channel called ${clone.name}`))
|
400
|
+
* .catch(console.error);
|
401
|
+
*/
|
402
|
+
clone(name = this.name, withPermissions = true, withTopic = true, reason) {
|
403
|
+
return this.guild.createChannel(name, {
|
404
|
+
type: this.type,
|
405
|
+
permissionOverwrites: withPermissions ? this.permissionOverwrites : undefined,
|
406
|
+
topic: withTopic ? this.topic : undefined,
|
407
|
+
reason,
|
408
|
+
});
|
409
|
+
}
|
410
|
+
|
411
|
+
/**
|
412
|
+
* Fetches a collection of invites to this guild channel.
|
413
|
+
* Resolves with a collection mapping invites by their codes.
|
414
|
+
* @returns {Promise<Collection<string, Invite>>}
|
415
|
+
*/
|
416
|
+
fetchInvites() {
|
417
|
+
return this.client.rest.makeRequest('get', Constants.Endpoints.Channel(this.id).invites, true)
|
418
|
+
.then(data => {
|
419
|
+
const invites = new Collection();
|
420
|
+
for (let invite of data) {
|
421
|
+
invite = new Invite(this.client, invite);
|
422
|
+
invites.set(invite.code, invite);
|
423
|
+
}
|
424
|
+
|
425
|
+
return invites;
|
426
|
+
});
|
427
|
+
}
|
428
|
+
|
429
|
+
/**
|
430
|
+
* Deletes this channel.
|
431
|
+
* @param {string} [reason] Reason for deleting this channel
|
432
|
+
* @returns {Promise<GuildChannel>}
|
433
|
+
* @example
|
434
|
+
* // Delete the channel
|
435
|
+
* channel.delete('Making room for new channels')
|
436
|
+
* .then(deleted => console.log(`Deleted ${deleted.name} to make room for new channels`))
|
437
|
+
* .catch(console.error);
|
438
|
+
*/
|
439
|
+
delete(reason) {
|
440
|
+
return this.client.rest.methods.deleteChannel(this, reason);
|
441
|
+
}
|
442
|
+
|
443
|
+
/**
|
444
|
+
* Checks if this channel has the same type, topic, position, name, overwrites and ID as another channel.
|
445
|
+
* In most cases, a simple `channel.id === channel2.id` will do, and is much faster too.
|
446
|
+
* @param {GuildChannel} channel Channel to compare with
|
447
|
+
* @returns {boolean}
|
448
|
+
*/
|
449
|
+
equals(channel) {
|
450
|
+
let equal = channel &&
|
451
|
+
this.id === channel.id &&
|
452
|
+
this.type === channel.type &&
|
453
|
+
this.topic === channel.topic &&
|
454
|
+
this.position === channel.position &&
|
455
|
+
this.name === channel.name;
|
456
|
+
|
457
|
+
if (equal) {
|
458
|
+
if (this.permissionOverwrites && channel.permissionOverwrites) {
|
459
|
+
equal = this.permissionOverwrites.equals(channel.permissionOverwrites);
|
460
|
+
} else {
|
461
|
+
equal = !this.permissionOverwrites && !channel.permissionOverwrites;
|
462
|
+
}
|
463
|
+
}
|
464
|
+
|
465
|
+
return equal;
|
466
|
+
}
|
467
|
+
|
468
|
+
/**
|
469
|
+
* Whether the channel is deletable by the client user
|
470
|
+
* @type {boolean}
|
471
|
+
* @readonly
|
472
|
+
*/
|
473
|
+
get deletable() {
|
474
|
+
return this.id !== this.guild.id &&
|
475
|
+
this.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS);
|
476
|
+
}
|
477
|
+
|
478
|
+
/**
|
479
|
+
* Whether the channel is manageable by the client user
|
480
|
+
* @type {boolean}
|
481
|
+
* @readonly
|
482
|
+
*/
|
483
|
+
get manageable() {
|
484
|
+
if (this.client.user.id === this.guild.ownerID) return true;
|
485
|
+
const permissions = this.permissionsFor(this.client.user);
|
486
|
+
if (!permissions) return false;
|
487
|
+
return permissions.has([Permissions.FLAGS.MANAGE_CHANNELS, Permissions.FLAGS.VIEW_CHANNEL]);
|
488
|
+
}
|
489
|
+
|
490
|
+
/**
|
491
|
+
* Whether the channel is muted
|
492
|
+
* <warn>This is only available when using a user account.</warn>
|
493
|
+
* @type {?boolean}
|
494
|
+
* @readonly
|
495
|
+
* @deprecated
|
496
|
+
*/
|
497
|
+
get muted() {
|
498
|
+
if (this.client.user.bot) return null;
|
499
|
+
try {
|
500
|
+
return this.client.user.guildSettings.get(this.guild.id).channelOverrides.get(this.id).muted;
|
501
|
+
} catch (err) {
|
502
|
+
return false;
|
503
|
+
}
|
504
|
+
}
|
505
|
+
|
506
|
+
/**
|
507
|
+
* The type of message that should notify you
|
508
|
+
* <warn>This is only available when using a user account.</warn>
|
509
|
+
* @type {?MessageNotificationType}
|
510
|
+
* @readonly
|
511
|
+
* @deprecated
|
512
|
+
*/
|
513
|
+
get messageNotifications() {
|
514
|
+
if (this.client.user.bot) return null;
|
515
|
+
try {
|
516
|
+
return this.client.user.guildSettings.get(this.guild.id).channelOverrides.get(this.id).messageNotifications;
|
517
|
+
} catch (err) {
|
518
|
+
return Constants.MessageNotificationTypes[3];
|
519
|
+
}
|
520
|
+
}
|
521
|
+
|
522
|
+
/**
|
523
|
+
* When concatenated with a string, this automatically returns the channel's mention instead of the Channel object.
|
524
|
+
* @returns {string}
|
525
|
+
* @example
|
526
|
+
* // Logs: Hello from <#123456789012345678>
|
527
|
+
* console.log(`Hello from ${channel}`);
|
528
|
+
* @example
|
529
|
+
* // Logs: Hello from <#123456789012345678>
|
530
|
+
* console.log('Hello from ' + channel);
|
531
|
+
*/
|
532
|
+
toString() {
|
533
|
+
return `<#${this.id}>`;
|
534
|
+
}
|
535
|
+
}
|
536
|
+
|
537
|
+
module.exports = GuildChannel;
|